Contents

NSTextSelectionManager

An object that coordinates text selection behavior for custom text views.

Declaration

@MainActor class NSTextSelectionManager

Mentioned in

Overview

NSTextSelectionManager provides a centralized way to manage text selection interactions using a set of gesture recognizers. For keyboard-based selection, integrate NSTextSelectionNavigation with your view. The selection manager works with a delegate to update and respond to selection changes, and with a data source to query the text layout system.

Gesture recognizer priority

Attach an NSTextSelectionManager to a view that isn’t NSTextView or NSTextField by setting the manager’s view property, and set its textSelectionDataSource property to your text layout object — typically an NSTextLayoutManager. Together, these give your custom view classic macOS text-selection behavior: bidirectional selection, drag-and-drop of text, and toggling.

NSTextSelectionManager builds on gesture recognizers. If you attach your own gesture recognizers to the same view, use gesturesForFailureRequirements to make your gesture recognizers wait for the selection manager’s gestures to fail before recognizing — so the selection manager gets first chance at the touch or click, instead of your gesture recognizers competing with it. For more information, see Prioritize gesture recognizers.

Topics

Setting a delegate

Configuring text selection

Managing gesture recognizers

See Also

Location and selection