Closed Yang-Xijie closed 3 years ago
Apologies, this is bad documentation. Obviously you should be able to copy-paste sample code and the code should work.
Swift is telling you it cannot automatically infer which callback you mean, so you should type your callback function. Try this:
struct ContentView: View {
@State var text: String = "**bold** _italic_"
var body: some View {
VStack {
HighlightedTextEditor(text: $text, highlightRules: .markdown)
.onSelectionChange { (range: NSRange) in // <--------------- NSRange
print(range)
}
}
}
}
I'll update the documentation if this works for you.
@Yang-Xijie Can you try the code I've provided above? Want to know if this works.
Sorry for replying late. It works! Thx a lot! 😃
Describe the bug
I want to create the editor App for macOS. But get the error
Ambiguous use of 'onSelectionChange'
in Xcode.To Reproduce
Steps to reproduce the behavior:
ContentView.swift
Ambiguous use of 'onSelectionChange'
and cannot build the project.Expected behavior I try that in iOS and it works just right. Printed out the NSRange when I make a selection.
Screenshots
Environment Please include:
Additional context English is not my native language; please excuse typing errors.