It's still using NSTextView inside. Here's a solution:
import SwiftUI
struct MyView: View {
@State var myString = "Hello world"
var body: some View {
TextEditor(text: $myString)
.onReceive(NotificationCenter.default.publisher(for: NSTextView.didChangeSelectionNotification), perform: { notification in
if let textView = notification.object as? NSTextView {
print(textView.selectedRange())
}
})
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: