<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextViewDelegate/textView(_:menu:for:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextViewDelegate(im)textView:menu:forEvent:atIndex:"
  },
  "title" : "textView(_:menu:for:at:)"
}
-->

# textView(_:menu:for:at:)

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

```
@MainActor optional func textView(_ view: NSTextView, menu: NSMenu, for event: NSEvent, at charIndex: Int) -> NSMenu?
```

## Parameters

`view`

The text view sending the message.

`menu`

The proposed contextual menu.

`event`

The mouse-down event that initiated the contextual menu’s display.

`charIndex`

The character position where the mouse button was clicked.

## Return Value

A menu to use as the contextual menu. You can return `menu` unaltered, or you can return a customized menu.

## Discussion

This method allows the delegate to control the context menu returned by [`menu(for:)`](/documentation/AppKit/NSView/menu(for:)).

---

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)