mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Handle file browser shortcuts in performKeyEquivalent:
This is called before the main menu acts on keys, and thus allows us to catch keys that are otherwise assigned to menu items. We only do this when the file browser is first responder, so it should be acceptable to have a few menu keys change behavior in that case.
This commit is contained in:
@@ -61,30 +61,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyDown:(NSEvent*)theEvent
|
||||
- (BOOL)performKeyEquivalent:(NSEvent*)anEvent
|
||||
{
|
||||
static struct key_action_t { std::string key; SEL action; } const KeyActions[] =
|
||||
if(self.window.firstResponder == self)
|
||||
{
|
||||
{ "@" + utf8::to_s(NSLeftArrowFunctionKey), @selector(goBack:) },
|
||||
{ "@" + utf8::to_s(NSRightArrowFunctionKey), @selector(goForward:) },
|
||||
{ utf8::to_s(NSCarriageReturnCharacter), @selector(performEditSelectedRow:) },
|
||||
{ utf8::to_s(NSEnterCharacter), @selector(performEditSelectedRow:) },
|
||||
{ "@" + utf8::to_s(NSDownArrowFunctionKey), @selector(performDoubleClick:) },
|
||||
{ "~" + utf8::to_s(NSF2FunctionKey), @selector(showContextMenu:) },
|
||||
{ "@o", @selector(performDoubleClick:) },
|
||||
{ "@d", @selector(duplicateSelectedEntries:) },
|
||||
{ "@G", @selector(orderFrontGoToFolder:) },
|
||||
{ " ", @selector(toggleQuickLookPreview:) },
|
||||
};
|
||||
static struct key_action_t { std::string key; SEL action; } const KeyActions[] =
|
||||
{
|
||||
{ "@" + utf8::to_s(NSLeftArrowFunctionKey), @selector(goBack:) },
|
||||
{ "@" + utf8::to_s(NSRightArrowFunctionKey), @selector(goForward:) },
|
||||
{ utf8::to_s(NSCarriageReturnCharacter), @selector(performEditSelectedRow:) },
|
||||
{ utf8::to_s(NSEnterCharacter), @selector(performEditSelectedRow:) },
|
||||
{ "@" + utf8::to_s(NSDownArrowFunctionKey), @selector(performDoubleClick:) },
|
||||
{ "~" + utf8::to_s(NSF2FunctionKey), @selector(showContextMenu:) },
|
||||
{ "@o", @selector(performDoubleClick:) },
|
||||
{ "@d", @selector(duplicateSelectedEntries:) },
|
||||
{ "@G", @selector(orderFrontGoToFolder:) },
|
||||
{ " ", @selector(toggleQuickLookPreview:) },
|
||||
};
|
||||
|
||||
std::string const key = to_s(theEvent);
|
||||
for(auto const& keyAction : KeyActions)
|
||||
{
|
||||
if(key == keyAction.key)
|
||||
return (void)[NSApp sendAction:keyAction.action to:nil from:self];
|
||||
std::string const key = to_s(anEvent);
|
||||
for(auto const& keyAction : KeyActions)
|
||||
{
|
||||
if(key == keyAction.key)
|
||||
return [NSApp sendAction:keyAction.action to:nil from:self];
|
||||
}
|
||||
}
|
||||
|
||||
[super keyDown:theEvent];
|
||||
return [super performKeyEquivalent:anEvent];
|
||||
}
|
||||
|
||||
- (void)draggingSession:(NSDraggingSession*)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation
|
||||
|
||||
Reference in New Issue
Block a user