Skip to content

Commit

Permalink
esc cancel input
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Jun 1, 2017
1 parent abdcd47 commit 665cfaf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/InputController.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,30 @@ -(BOOL)onKeyEvent:(NSEvent*)event client:(id)sender{
NSString* string = [event characters];

NSString* bufferedText = [self originalBuffer];
bool hasBufferedText = bufferedText && [bufferedText length] > 0;

// NSLog(@"text:%@, keycode:%ld, %ld, bufferedText:%@", string, (long)keyCode,
// [event modifierFlags] & NSShiftKeyMask, bufferedText);


if(keyCode == KEY_DELETE){
if ( bufferedText && [bufferedText length] > 0 ) {
if (hasBufferedText) {
return [self deleteBackward:sender];
}

return NO;
}

if(keyCode == KEY_RETURN){
if ( bufferedText && [bufferedText length] > 0 ) {
if (hasBufferedText) {
[self commitComposition:sender];
return YES;
}
return NO;
}

if(keyCode == KEY_SPACE){
if ( bufferedText && [bufferedText length] > 0 ) {
if (hasBufferedText) {
[self appendToComposedBuffer: @" "];
[self commitComposition:sender];
return YES;
Expand All @@ -107,11 +108,11 @@ -(BOOL)onKeyEvent:(NSEvent*)event client:(id)sender{
}

if(keyCode == KEY_ESC){
if ( bufferedText && [bufferedText length] > 0 ) {
if (hasBufferedText) {
[self cancelComposition];
[self setComposedBuffer:@""];
[self setOriginalBuffer:@""];
[self commitComposition:sender];

return YES;
}
return NO;
}
Expand All @@ -127,7 +128,7 @@ -(BOOL)onKeyEvent:(NSEvent*)event client:(id)sender{

if ([[NSCharacterSet punctuationCharacterSet] characterIsMember: ch] ||
[[NSCharacterSet symbolCharacterSet] characterIsMember: ch]) {
if (bufferedText && [bufferedText length] > 0) {
if (hasBufferedText) {
[self appendToComposedBuffer: string];
[self commitComposition:sender];
return YES;
Expand Down

0 comments on commit 665cfaf

Please sign in to comment.