Last active
August 2, 2024 07:42
-
-
Save matthewreagan/02b6fefa537d67832ff8 to your computer and use it in GitHub Desktop.
Fixing control-click vs right-click contextual menus in NSView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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