replaceSelectedText(_:withText:)
Replaces text with new text, either within the current selection or near the cursor.
Declaration
func replaceSelectedText(_ text: String, withText replacementText: String)Parameters
- text:
The text to find and replace.
- replacementText:
The text to insert in place of the found text.
Mentioned in
Discussion
This method’s behavior depends on the current selection state:
If text is selected, this method replaces occurrences of
textwithin the selection withreplacementText.If the cursor is positioned without a selection, this method searches for
textimmediately before the cursor and replaces it withreplacementText.If the cursor is at the start of an editable element, this method searches for
textimmediately after the cursor instead.