Skip to content

Instantly share code, notes, and snippets.

@milk1000cc
Created December 12, 2010 04:38
Show Gist options
  • Save milk1000cc/737855 to your computer and use it in GitHub Desktop.
Save milk1000cc/737855 to your computer and use it in GitHub Desktop.
Index: iTermApplication.m
===================================================================
--- iTermApplication.m (revision 404)
+++ iTermApplication.m (working copy)
@@ -62,6 +62,11 @@
PTYTabView* tabView = [currentTerminal tabView];
PTYSession* currentSession = [currentTerminal currentSession];
NSResponder *responder;
+ unsigned short keyCode = [event keyCode];
+ unsigned int modifierFlags = [event modifierFlags];
+ const int modifierMask = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask;
+ int uiModifier = NSCommandKeyMask;
+ int commandKeyAsMeta = 1;
if (([event modifierFlags] & (NSCommandKeyMask | NSAlternateKeyMask)) == (NSCommandKeyMask | NSAlternateKeyMask)) {
// Command-Alt number: Switch to window by number.
@@ -101,22 +106,59 @@
return;
}
- const int mask = NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask;
- if (([event modifierFlags] & mask) == NSCommandKeyMask) {
- int digit = [[event charactersIgnoringModifiers] intValue];
- if (digit >= 1 && digit <= [tabView numberOfTabViewItems]) {
- // Command+number: Switch to tab by number.
- [tabView selectTabViewItemAtIndex:digit-1];
+ if (commandKeyAsMeta) {
+ uiModifier = NSAlternateKeyMask;
+ }
+
+ if((modifierFlags & modifierMask) == uiModifier) {
+ switch (keyCode)
+ {
+ case 0x12:case 0x13:case 0x14:// 1 2 3
+ case 0x15:case 0x17:case 0x16:// 4 5 6
+ case 0x1a:case 0x1c:case 0x19:// 7 8 9
+ {
+ int digit = [[event charactersIgnoringModifiers] intValue];
+ if(digit >= 1 && digit <= [tabView numberOfTabViewItems]) {
+ [tabView selectTabViewItemAtIndex:digit-1];
+ return;
+ }
+ }
+ }
+ }
+
+ if (inTextView) {
+ if (commandKeyAsMeta) {
+ NSString* charactersIgnoringModifiers = [event charactersIgnoringModifiers];
+ if((modifierFlags & NSCommandKeyMask) == NSCommandKeyMask) {
+ [currentSession keyDown:event];
+ return;
+ } else if((modifierFlags & NSAlternateKeyMask) == NSAlternateKeyMask) {
+ NSEvent* newEvent;
+ NSString* newstr = charactersIgnoringModifiers;
+
+ modifierFlags -= NSAlternateKeyMask;
+ modifierFlags |= NSCommandKeyMask;
+ newEvent = [NSEvent keyEventWithType: [event type]
+ location: [event locationInWindow]
+ modifierFlags: modifierFlags
+ timestamp: [event timestamp]
+ windowNumber: [event windowNumber]
+ context: [event context]
+ characters: newstr
+ charactersIgnoringModifiers: newstr
+ isARepeat: [event isARepeat]
+ keyCode: keyCode];
+ [super sendEvent: newEvent];
+ return;
+ }
+ }
+
+ if ([currentSession hasKeyMappingForEvent:event highPriority:YES]) {
+ // Remap key.
+ [currentSession keyDown:event];
return;
}
}
-
- if (inTextView &&
- [currentSession hasKeyMappingForEvent:event highPriority:YES]) {
- // Remap key.
- [currentSession keyDown:event];
- return;
- }
}
}
Index: PTYSession.m
===================================================================
--- PTYSession.m (revision 404)
+++ PTYSession.m (working copy)
@@ -737,6 +737,14 @@
send_str = (unsigned char *)[keydat bytes];
send_strlen = [keydat length];
}
+ } else if ((modflag & NSCommandKeyMask) &&
+ (unicode != 0x20 &&
+ unicode != 0x74 &&
+ unicode != NSLeftArrowFunctionKey &&
+ unicode != NSRightArrowFunctionKey)) {
+ send_str = (unsigned char *)strdup("\x1b ");
+ send_strlen = 2;
+ send_str[1] = (unsigned char)unicode;
} else if (((modflag & NSLeftAlternateKeyMask) == NSLeftAlternateKeyMask &&
([self optionKey] != OPT_NORMAL)) ||
((modflag & NSRightAlternateKeyMask) == NSRightAlternateKeyMask &&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment