smartInsert(for:replacing:before:after:)
Determines whether whitespace needs to be added around the string to preserve proper spacing and punctuation when it replaces the characters in the specified range.
Declaration
func smartInsert(for pasteString: String, replacing charRangeToReplace: NSRange, before beforeString: AutoreleasingUnsafeMutablePointer<NSString?>?, after afterString: AutoreleasingUnsafeMutablePointer<NSString?>?)Parameters
- pasteString:
The string that is replacing the characters in
charRange. - charRangeToReplace:
The range of characters which
aStringis replacing. - beforeString:
On return, a pointer to the string with the characters that should be added before
aString;nilif there are no characters to add, ifaStringisnil, or if smart insertion and deletion are disabled. - afterString:
On return, a pointer to the string with the characters that should be added after
aString;nilif there are no characters to add, ifaStringisnil, or if smart insertion and deletion are disabled.
Discussion
As part of its implementation, this method calls smartInsert(afterStringFor:replacing:) and smartInsert(beforeStringFor:replacing:). To change this method’s behavior, override those two methods instead of this one.
NSTextView uses this method as necessary. You can also use it in implementing your own methods that insert text. To do so, invoke this method with the proper arguments, then insert beforeString, aString, and afterString in order over charRange.
See Also
Customizing subclass behaviors
updateFontPanel()updateRuler()acceptableDragTypesupdateDragTypeRegistration()selectionRange(forProposedRange:granularity:)rangeForUserCharacterAttributeChangerangesForUserCharacterAttributeChangerangeForUserParagraphAttributeChangerangesForUserParagraphAttributeChangerangeForUserTextChangerangesForUserTextChangeshouldChangeText(in:replacementString:)shouldChangeText(inRanges:replacementStrings:)didChangeText()smartInsertDeleteEnabled