Instance Method

shouldChangeTextInRanges:replacementStrings:

Initiates a series of delegate messages (and general notifications) to determine whether modifications can be made to the characters and attributes of the receiver’s text.

Declaration

- (BOOL)shouldChangeTextInRanges:(NSArray<NSValue *> *)affectedRanges replacementStrings:(NSArray<NSString *> *)replacementStrings;

Parameters

affectedRanges

An array of ranges to change.

replacementStrings

An array of strings containing the characters that replace those in affectedRanges, one for each range. If only text attributes are being changed, replacementStrings is nil.

Return Value

YES to allow the change, NO to prohibit it.

Discussion

This method checks with the delegate as needed using textShouldBeginEditing: and textView:shouldChangeTextInRanges:replacementStrings:.

This method must be invoked at the start of any sequence of user-initiated editing changes. If your subclass of NSTextView implements

that modify the text, make sure to invoke this method to determine whether the change should be made. If the change is allowed, complete the change by invoking the didChangeText method. If you can’t determine the affected range or replacement string before beginning changes, pass nil for these values.

Special Considerations

If you override this method, you must call super at the beginning of the override.

If the receiver is not editable, this method automatically returns NO. This result prevents instances in which a text view could be changed by user actions even though it had been set to be non-editable.

See Also

Methods for Subclasses to Use or Override

- updateFontPanel

Updates the Font panel to contain the font attributes of the selection.

- updateRuler

Updates the ruler view in the receiver’s enclosing scroll view to reflect the selection’s paragraph and marker attributes.

acceptableDragTypes

The data types that the receiver accepts as the destination view of a dragging operation.

- updateDragTypeRegistration

Updates the acceptable drag types of all text views associated with the receiver's layout manager.

- selectionRangeForProposedRange:granularity:

Returns an adjusted selected range based on the selection granularity.

rangeForUserCharacterAttributeChange

The range of characters affected by an action method that changes character (not paragraph) attributes.

rangesForUserCharacterAttributeChange

An array containing the ranges of characters affected by an action method that changes character (not paragraph) attributes.

rangeForUserParagraphAttributeChange

The range of characters affected by an action method that changes paragraph (not character) attributes.

rangesForUserParagraphAttributeChange

An array containing the ranges of characters affected by a method that changes paragraph (not character) attributes.

rangeForUserTextChange

The range of characters affected by a method that changes characters (as opposed to attributes).

rangesForUserTextChange

An array containing the ranges of characters affected by a method that changes characters (as opposed to attributes).

- shouldChangeTextInRange:replacementString:

Initiates a series of delegate messages (and general notifications) to determine whether modifications can be made to the characters and attributes of the receiver’s text.

- didChangeText

Sends out necessary notifications when a text change completes.

smartInsertDeleteEnabled

A Boolean value that controls whether the receiver inserts or deletes space around selected words so as to preserve proper spacing and punctuation.

- smartDeleteRangeForProposedRange:

Returns an extended range that includes adjacent whitespace that should be deleted along with the proposed range in order to preserve proper spacing and punctuation.

- smartInsertAfterStringForString:replacingRange:

Returns any whitespace that needs to be added after the string to preserve proper spacing and punctuation when the string replaces the characters in the specified range.

- smartInsertBeforeStringForString:replacingRange:

Returns any whitespace that needs to be added before the string to preserve proper spacing and punctuation when the string replaces the characters in the specified range.

- smartInsertForString:replacingRange:beforeString:afterString:

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.

- toggleSmartInsertDelete:

Changes the state of smart insert and delete from enabled to disabled and vice versa.