Non-active text views only execute bundle items with ⌘ in their shortcut

In general only the active view should respond to keys but we have the text view handle bundle items because they can provide actions that are not tied to text editing, for example “Build” or “Show SCM Actions”.

Ideally bundle items would (also) be handled by the window controller, but keyDown: is not commonly passed up the responder chain, so our window controller never sees any keys.

The way the system is designed is that the menu system will resolve keys (before the active view) and then send the menu item’s action up the responder chain, so views respond to actions rather than keys, but we cannot use this system for bundle items because it does not support multiple items with same key equivalent or scope selectors.
This commit is contained in:
Allan Odgaard
2016-07-03 20:34:41 +02:00
parent d3f7193415
commit 94036f28aa

View File

@@ -1961,8 +1961,11 @@ static void update_menu_key_equivalents (NSMenu* menu, std::multimap<std::string
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
{
BOOL hasFocus = (self.keyState & (OakViewViewIsFirstResponderMask|OakViewWindowIsKeyMask|OakViewApplicationIsActiveMask)) == (OakViewViewIsFirstResponderMask|OakViewWindowIsKeyMask|OakViewApplicationIsActiveMask);
if(!hasFocus && ([[[self window] firstResponder] isKindOfClass:[self class]] || [[[self window] firstResponder] isKindOfClass:NSClassFromString(@"OakKeyEquivalentView")]))
BOOL hasKey = (self.keyState & (OakViewViewIsFirstResponderMask|OakViewWindowIsKeyMask|OakViewApplicationIsActiveMask)) == (OakViewViewIsFirstResponderMask|OakViewWindowIsKeyMask|OakViewApplicationIsActiveMask);
BOOL otherTextViewHasKey = [self.window.firstResponder isKindOfClass:[self class]];
BOOL recordingShortcut = [self.window.firstResponder isKindOfClass:NSClassFromString(@"OakKeyEquivalentView")];
BOOL noCommandFlag = (anEvent.modifierFlags & NSCommandKeyMask) != NSCommandKeyMask;
if(!hasKey && (otherTextViewHasKey || recordingShortcut || noCommandFlag))
return NO;
D(DBF_OakTextView_TextInput, bug("%s\n", [[anEvent description] UTF8String]););