CodeEditor
CodeEditor copied to clipboard
Problems using ColorPicker and CodeEditor at the same time
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
I still think that this is likely a bug in SwiftUI itself, not in the CodeEditor.
Though two color pickers work alongside.
I wonder whether the behaviour is actually intentional. I.e. the NSColorWell is active, and you pick the color in some text field π€
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!!!
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.