Instance Method


Sets the selection to a range of characters in response to user action.


- (void)setSelectedRange:(NSRange)charRange affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)stillSelectingFlag;



The range of characters to select. This range must begin and end on glyph boundaries and not split base glyphs and their nonspacing marks.


The selection affinity for the selection. See selectionAffinity for more information about how affinities work.


YES to behave appropriately for a continuing selection where the user is still dragging the mouse, NO otherwise. If YES, the receiver doesn’t send notifications or remove the marking from its marked text. If NO, the receiver posts an NSTextViewDidChangeSelectionNotification to the default notification center and removes the marking from marked text if the new selection is greater than the marked region.


This method resets the selection granularity to NSSelectByCharacter.

Special Considerations

In macOS 10.4 and later, if there are multiple selections, this method acts on the first selected subrange.

See Also

Managing the Selection


An array containing the ranges of characters selected in the receiver’s layout manager.

- setSelectedRange:

Sets the selection to the characters in an array of ranges.

- setSelectedRanges:affinity:stillSelecting:

Sets the selection to the characters in an array of ranges in response to user action.


The preferred direction of selection.


The selection granularity for subsequent extension of a selection.


The color of the insertion point.

- updateInsertionPointStateAndRestartTimer:

Updates the insertion point’s location and optionally restarts the blinking cursor timer.


The attributes used to indicate the selection.


The attributes used to draw marked text.


The attributes used to draw the onscreen presentation of link text.

- characterIndexForInsertionAtPoint:

Returns a character index appropriate for placing a zero-length selection for an insertion point associated with the mouse at the given point.