Post not yet marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
contentPostList.repliesup-voted.tooltip
Replied In
Getting SwiftUI TextEditor's Selection Range
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())
}
})
}
}