CodeEditor icon indicating copy to clipboard operation
CodeEditor copied to clipboard

Problems using ColorPicker and CodeEditor at the same time

Open SNQ-2001 opened this issue 2 years ago β€’ 5 comments

I found a new issue regarding the relationship between ColorPicker and CodeEditor

(1) Start ColorPicker (2) Double-tap Text in CodeEditor

↓ Result ↓

The color of the Text is reflected in the ColorPicker

import SwiftUI
import CodeEditor

struct ContentView: View {
    @State var source: String = """
import SwiftUI
import CodeEditor

struct ContentView: View {
    @State var source: String = ""
    @State var color: Color = Color.white
    var body: some View {
        HStack {
            ColorPicker("", selection: $color)
            CodeEditor(source: $source)
        }
    }
}
"""
    @State var color: Color = Color.white
    var body: some View {
        ZStack {
            color
                .edgesIgnoringSafeArea(.all)
            HStack {
                ColorPicker("ColorPicker", selection: $color)
                CodeEditor(source: $source, language: .swift, theme: .pojoaque)
            }
        }
    }
}

https://user-images.githubusercontent.com/84154073/164490460-6978fbbb-2afc-4e30-973b-87aae9435ae5.mp4

SNQ-2001 avatar Apr 21 '22 15:04 SNQ-2001

I still think that this is likely a bug in SwiftUI itself, not in the CodeEditor.

helje5 avatar Apr 21 '22 15:04 helje5

Though two color pickers work alongside.

helje5 avatar Apr 21 '22 15:04 helje5

I wonder whether the behaviour is actually intentional. I.e. the NSColorWell is active, and you pick the color in some text field πŸ€”

helje5 avatar Apr 21 '22 15:04 helje5

If it's a SwiftUI bug, there's nothing we can do about it😭 We can only hope for the development of SwiftUI

CodeEditor is a great OSS! Thanks for creating it!!!

SNQ-2001 avatar Apr 21 '22 15:04 SNQ-2001

I'm not quite sure yet, maybe it isn't even a bug. I have the feeling the colorwell should resign being active (and stop tracking the NSColorPanel) if the NSTextView becomes first responder again.

helje5 avatar Apr 21 '22 15:04 helje5