Closed danielsaidi closed 1 month ago
Thank you again for your truly impressive library. What a gift!
It appears to already be possible (early Aug '23) to replace text at a specific offset:
context.pasteText("<some text>", at: <some offset>, moveCursorToPastedContent: T/F)
But yes, a range would definitely be more usable. However, the solution should support styled text (ie, NSAttributedString) as well. For example:
let attr = [NSAttributedString.Key.foregroundColor: UIColor.lightGray, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 24]
let text = NSMutableAttributedString(string: "<some text here>\n", attributes: attr)
<magic>.replaceText(in: context.selectedRange, with: text)
FWIW, pasteText() does not appear to accommodate styled text.
Hi @savanteer
Thanks for your feedback! I hope to have time to work on this in a few weeks.
I have added an action-based way of doing this.
It's merged into main
and will be available in 1.1
.
We can currently use the context to select a range, but not replace the currently selected text.
This should be possible when replacing text.
Replace the
pasteText
function with aninsertText(at: position)
(non-replacing) andinsertText(at: range)
(replacing).