<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextViewDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextViewDelegate"
  },
  "title" : "NSTextViewDelegate"
}
-->

# NSTextViewDelegate

A set of optional methods that text view delegates can use to manage selection, set text attributes, work with the spell checker, and more.

```
protocol NSTextViewDelegate : NSTextDelegate
```

## Topics

### Accessing Text System Objects

[`-  undoManagerForTextView:`](/documentation/AppKit/NSTextViewDelegate/undoManager(for:))

Returns the undo manager for the specified text view.

### Controlling Display

[`-  textView:willDisplayToolTip:forCharacterAtIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:willDisplayToolTip:forCharacterAt:))

Returns the actual tooltip to display.

### Supporting Quick Look

[`-  textView:URLForContentsOfTextAttachment:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:urlForContentsOf:at:))

Returns a URL representing the document contents for a text attachment.

### Managing the Selection

[`-  textView:willChangeSelectionFromCharacterRange:toCharacterRange:`](/documentation/AppKit/NSTextViewDelegate/textView(_:willChangeSelectionFromCharacterRange:toCharacterRange:))

Returns the actual range to select.

[`-  textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:`](/documentation/AppKit/NSTextViewDelegate/textView(_:willChangeSelectionFromCharacterRanges:toCharacterRanges:))

Returns the actual character ranges to select.

[`-  textViewDidChangeSelection:`](/documentation/AppKit/NSTextViewDelegate/textViewDidChangeSelection(_:))

Sent when the selection changes in the text view.

[`-  textView:candidates:forSelectedRange:`](/documentation/AppKit/NSTextViewDelegate/textView(_:candidates:forSelectedRange:))

Returns an array of text objects to include in a text selection.

[`-  textView:candidatesForSelectedRange:`](/documentation/AppKit/NSTextViewDelegate/textView(_:candidatesForSelectedRange:))

Returns an array of objects that represent the elements of a selection.

[`-  textView:shouldSelectCandidateAtIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldSelectCandidateAt:))

Returns a Boolean value that indicates whether to select the text object at the index.

[`-  textView:shouldUpdateTouchBarItemIdentifiers:`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldUpdateTouchBarItemIdentifiers:))

Returns and array of touch bar elements for the framework to update.

### Managing the Pasteboard

[`-  textView:writablePasteboardTypesForCell:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:writablePasteboardTypesFor:at:))

Returns the writable pasteboard types for a given cell.

[`-  textView:writeCell:atIndex:toPasteboard:type:`](/documentation/AppKit/NSTextViewDelegate/textView(_:write:at:to:type:))

Returns whether data of the specified type for the given cell could be written to the specified pasteboard.

### Setting Text Attributes

[`-  textView:shouldChangeTextInRange:replacementString:`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldChangeTextIn:replacementString:))

Sent when a text view needs to determine if text in a specified range should be changed.

[`-  textView:shouldChangeTextInRanges:replacementStrings:`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldChangeTextInRanges:replacementStrings:))

Sent when a text view needs to determine if text in an array of specified ranges should be changed.

[`-  textView:shouldChangeTypingAttributes:toAttributes:`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldChangeTypingAttributes:toAttributes:))

Sent when the typing attributes are changed.

[`-  textViewDidChangeTypingAttributes:`](/documentation/AppKit/NSTextViewDelegate/textViewDidChangeTypingAttributes(_:))

Sent when a text view’s typing attributes change.

### Clicking and Pasting

[`-  textView:clickedOnCell:inRect:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:clickedOn:in:at:))

Sent when the user clicks a cell.

[`-  textView:doubleClickedOnCell:inRect:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:doubleClickedOn:in:at:))

Sent when the user double-clicks a cell.

[`-  textView:clickedOnLink:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:clickedOnLink:at:))

Sent after the user clicks a link.

### Working With the Spelling Checker

[`-  textView:shouldSetSpellingState:range:`](/documentation/AppKit/NSTextViewDelegate/textView(_:shouldSetSpellingState:range:))

Sent when the spelling state is changed.

[`-  textView:willCheckTextInRange:options:types:`](/documentation/AppKit/NSTextViewDelegate/textView(_:willCheckTextIn:options:types:))

Invoked to allow the delegate to modify the text checking process before it occurs.

[`-  textView:didCheckTextInRange:types:options:results:orthography:wordCount:`](/documentation/AppKit/NSTextViewDelegate/textView(_:didCheckTextIn:types:options:results:orthography:wordCount:))

Invoked to allow the delegate to modify the text checking results after checking has occurred.

### Responding to writing tools interactions

[`-  textViewWritingToolsWillBegin:`](/documentation/AppKit/NSTextViewDelegate/textViewWritingToolsWillBegin(_:))

[`-  textViewWritingToolsDidEnd:`](/documentation/AppKit/NSTextViewDelegate/textViewWritingToolsDidEnd(_:))

[`-  textView:writingToolsIgnoredRangesInEnclosingRange:`](/documentation/AppKit/NSTextViewDelegate/textView(_:writingToolsIgnoredRangesInEnclosingRange:))

### Dragging

[`-  textView:draggedCell:inRect:event:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:draggedCell:in:event:at:))

Sent when the user attempts to drag a cell.

### Completing text

[`-  textView:completions:forPartialWordRange:indexOfSelectedItem:`](/documentation/AppKit/NSTextViewDelegate/textView(_:completions:forPartialWordRange:indexOfSelectedItem:))

Returns the actual completions for a partial word.

### Displaying the sharing service picker

[`-  textView:willShowSharingServicePicker:forItems:`](/documentation/AppKit/NSTextViewDelegate/textView(_:willShow:forItems:))

Returns a sharing service picker for the current selection.

### Performing Commands

[`-  textView:doCommandBySelector:`](/documentation/AppKit/NSTextViewDelegate/textView(_:doCommandBy:))

Sent to allow the delegate to perform the command for the text view.

### Contextual Menu Management

[`-  textView:menu:forEvent:atIndex:`](/documentation/AppKit/NSTextViewDelegate/textView(_:menu:for:at:))

Allows delegate to control the context menu returned by the text view.

### Deprecated Methods

[`-  textView:clickedOnLink:`](/documentation/AppKit/NSTextViewDelegate/textView:clickedOnLink:)

Sent after the user clicks on a link.

[`-  textView:draggedCell:inRect:event:`](/documentation/AppKit/NSTextViewDelegate/textView:draggedCell:inRect:event:)

Sent when the user attempts to drag a cell.

[`-  textView:clickedOnCell:inRect:`](/documentation/AppKit/NSTextViewDelegate/textView:clickedOnCell:inRect:)

Sent when the user clicks a cell.

[`-  textView:doubleClickedOnCell:inRect:`](/documentation/AppKit/NSTextViewDelegate/textView:doubleClickedOnCell:inRect:)

Sent when the user double-clicks a cell.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSTextDelegate`](/documentation/AppKit/NSTextDelegate)

### Conforming Types

[`NSTableView`](/documentation/AppKit/NSTableView)

[`NSOutlineView`](/documentation/AppKit/NSOutlineView)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)