diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 54417f6f..9cce3627 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -243,7 +243,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) { BOOL result = [_keyHandler handleInput:input state:_state stateCallback:^(InputState *state) { [self handleState:state client:client]; } candidateSelectionCallback:^{ -// NSLog(@"candidate window updated."); + NSLog(@"candidate window updated."); } errorCallback:^{ NSBeep(); }]; @@ -295,7 +295,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) { - (void)handleState:(InputState *)newState client:(id)client { -// NSLog(@"current state: %@ new state: %@", _state, newState ); + NSLog(@"new state: %@ / current state: %@", newState, _state); // We need to set the state to the member variable since the candidate // window need to read the candidates from it. @@ -408,15 +408,8 @@ static inline NSString *LocalizationNotNeeded(NSString *s) { // i.e. the client app needs to take care of where to put ths composing buffer [client setMarkedText:attrString selectionRange:NSMakeRange(cursorIndex, 0) replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; - if (_keyHandler.inputMode == kPlainBopomofoModeIdentifier && state.candidates.count == 1) { - NSString *buffer = [self _convertToSimplifiedChineseIfRequired:state.candidates.firstObject]; - [client insertText:buffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; - InputStateEmpty *empty = [[InputStateEmpty alloc] init]; - [self handleState:empty client:client]; - } else { - if (![previous isKindOfClass:[InputStateChoosingCandidate class]]) { - [self _showCandidateWindowWithState:state client:client]; - } + if (![previous isKindOfClass:[InputStateChoosingCandidate class]]) { + [self _showCandidateWindowWithState:state client:client]; } } diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index 5ee9135d..a9002333 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -343,7 +343,15 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot if (_inputMode == kPlainBopomofoModeIdentifier) { InputStateChoosingCandidate *choosingCandidates = [self _buildCandidateState:inputting useVerticalMode:input.useVerticalMode]; - stateCallback(choosingCandidates); + if (choosingCandidates.candidates.count == 1) { + [self clear]; + InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:choosingCandidates.candidates.firstObject]; + stateCallback(committing); + InputStateEmpty *empty = [[InputStateEmpty alloc] init]; + stateCallback(empty); + } else { + stateCallback(choosingCandidates); + } } // and tells the client that the key is consumed @@ -699,13 +707,20 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot - (BOOL)_handleEnterWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback { if ([state isKindOfClass:[InputStateInputting class]]) { + if (_inputMode == kPlainBopomofoModeIdentifier) { + if (!_bpmfReadingBuffer->isEmpty()) { + errorCallback(); + } + return YES; + } + [self clear]; InputStateInputting *current = (InputStateInputting *) state; NSString *composingBuffer = current.composingBuffer; InputStateCommitting *committing = [[InputStateCommitting alloc] initWithPoppedText:composingBuffer]; stateCallback(committing); - InputState *empty = [[InputState alloc] init]; + InputStateEmpty *empty = [[InputStateEmpty alloc] init]; stateCallback(empty); return YES; } @@ -991,7 +1006,8 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot if (candidateIndex != NSUIntegerMax) { [self.delegate keyHandler:self didSelectCandidateAtIndex:candidateIndex candidateController:gCurrentCandidateController]; [self clear]; - InputStateEmpty *empty = [[InputStateEmpty alloc] init]; + InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init]; + stateCallback(empty); [self handleInput:input state:empty stateCallback:stateCallback candidateSelectionCallback:candidateSelectionCallback errorCallback:errorCallback]; } return YES;