Skip to content

Commit

Permalink
Fix control+key for custom layouts. Fixes bug 1097.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Jul 13, 2011
1 parent a5ed29d commit 97910b8
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions PTYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1897,15 +1897,48 @@ - (void)keyDown:(NSEvent*)event
return;
}

// Let the IME process key events
IM_INPUT_INSERT = NO;
[self interpretKeyEvents:[NSArray arrayWithObject:event]];

// If the IME didn't want it, pass it on to the delegate
// Control+Key doesn't work right with custom keyboard layouts. Handle ctrl+key here for the
// standard combinations.
BOOL workAroundControlBug = NO;
if (!prev &&
!IM_INPUT_INSERT &&
![self hasMarkedText]) {
[delegate keyDown:event];
(modflag & (NSControlKeyMask | NSCommandKeyMask | NSAlternateKeyMask)) == NSControlKeyMask) {
NSString *unmodkeystr = [event charactersIgnoringModifiers];
if ([unmodkeystr length] != 0) {
unichar unmodunicode = [unmodkeystr length] > 0 ? [unmodkeystr characterAtIndex:0] : 0;
unichar cc = 0xffff;
if (unmodunicode >= 'a' && unmodunicode <= 'z') {
cc = unmodunicode - 'a' + 1;
} else if (unmodunicode == ' ' || unmodunicode == '2' || unmodunicode == '@') {
cc = 0;
} else if (unmodunicode == '[') { // esc
cc = 27;
} else if (unmodunicode == '\\') {
cc = 28;
} else if (unmodunicode == ']') {
cc = 29;
} else if (unmodunicode == '^' || unmodunicode == '6') {
cc = 30;
} else if (unmodunicode == '-' || unmodunicode == '_') {
cc = 31;
}
if (cc != 0xffff) {
[self insertText:[NSString stringWithCharacters:&cc length:1]];
workAroundControlBug = YES;
}
}
}

if (!workAroundControlBug) {
// Let the IME process key events
IM_INPUT_INSERT = NO;
[self interpretKeyEvents:[NSArray arrayWithObject:event]];

// If the IME didn't want it, pass it on to the delegate
if (!prev &&
!IM_INPUT_INSERT &&
![self hasMarkedText]) {
[delegate keyDown:event];
}
}
}

Expand Down

0 comments on commit 97910b8

Please sign in to comment.