Skip to content

Instantly share code, notes, and snippets.

@matthewreagan
Last active August 2, 2024 07:42
Show Gist options
  • Save matthewreagan/02b6fefa537d67832ff8 to your computer and use it in GitHub Desktop.
Save matthewreagan/02b6fefa537d67832ff8 to your computer and use it in GitHub Desktop.
Fixing control-click vs right-click contextual menus in NSView
override func mouseDown(theEvent: NSEvent)
{
/* Hard-coding this behavior isn't great, and shouldn't be necessary. (It should
be up to OS X to define what a contextual-menu click is/isn't, and we should
only care about vending our NSMenu via `menuForEvent:`). */
let modifierFlags = theEvent.modifierFlags;
if (modifierFlags.contains(.ControlKeyMask))
{
if let menu = self.menuForEvent(theEvent)
{
NSMenu.popUpContextMenu(menu, withEvent:theEvent, forView:self);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment