Fixes the issue on presenting the candidate window.

This commit is contained in:
zonble 2022-01-28 01:44:50 +08:00
parent fc0c077193
commit 9351d877ba
1 changed files with 18 additions and 30 deletions

View File

@ -1311,32 +1311,26 @@ static double FindHighestScore(const vector<NodeAnchor> &nodes, double epsilon)
- (void)handleState:(InputState *)newState client:(id)client - (void)handleState:(InputState *)newState client:(id)client
{ {
NSLog(@"current state: %@ new state: %@", _state, newState ); // NSLog(@"current state: %@ new state: %@", _state, newState );
// We need to set the state to the member varible since the candidate
// window need to read the candidates from it.
InputState *previous = _state;
_state = newState;
if ([newState isKindOfClass:[InputStateDeactive class]]) { if ([newState isKindOfClass:[InputStateDeactive class]]) {
[self _handleInputStateDeactive:(InputStateDeactive *) newState previous:_state client:client]; [self _handleInputStateDeactive:(InputStateDeactive *) newState previous:previous client:client];
} else if ([newState isKindOfClass:[InputStateEmpty class]]) {
[self _handleInputStateEmpty:(InputStateEmpty *) newState previous:previous client:client];
} else if ([newState isKindOfClass:[InputStateCommitting class]]) {
[self _handleInputStateCommitting:(InputStateCommitting *) newState previous:previous client:client];
} else if ([newState isKindOfClass:[InputStateInputting class]]) {
[self _handleInputStateInputting:(InputStateInputting *) newState previous:previous client:client];
} else if ([newState isKindOfClass:[InputStateMarking class]]) {
[self _handleInputStateMarking:(InputStateMarking *) newState previous:previous client:client];
} else if ([newState isKindOfClass:[InputStateChoosingCandidate class]]) {
[self _handleInputStateChoosingCandidate:(InputStateChoosingCandidate *)newState previous:previous client:client];
} }
if ([newState isKindOfClass:[InputStateEmpty class]]) {
[self _handleInputStateEmpty:(InputStateEmpty *) newState previous:_state client:client];
}
if ([newState isKindOfClass:[InputStateCommitting class]]) {
[self _handleInputStateCommitting:(InputStateCommitting *) newState previous:_state client:client];
}
if ([newState isKindOfClass:[InputStateInputting class]]) {
[self _handleInputStateInputting:(InputStateInputting *) newState previous:_state client:client];
}
if ([newState isKindOfClass:[InputStateMarking class]]) {
[self _handleInputStateMarking:(InputStateMarking *) newState previous:_state client:client];
}
if ([newState isKindOfClass:[InputStateChoosingCandidate class]]) {
[self _handleInputStateChoosingCandidate:(InputStateChoosingCandidate *)newState previous:_state client:client];
}
_state = newState;
} }
- (void)_handleInputStateDeactive:(InputStateDeactive *)state previous:(InputState *)previous client:(id)client - (void)_handleInputStateDeactive:(InputStateDeactive *)state previous:(InputState *)previous client:(id)client
@ -1421,24 +1415,18 @@ static double FindHighestScore(const vector<NodeAnchor> &nodes, double epsilon)
{ {
NSUInteger cursorIndex = [state cursorIndex]; NSUInteger cursorIndex = [state cursorIndex];
NSAttributedString *attrString = [state attributedString]; NSAttributedString *attrString = [state attributedString];
NSLog(@"_handleInputStateChoosingCandidate 1");
NSLog(@"isMainThread :%d", [NSThread isMainThread]);
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put ths composing buffer // 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)]; [client setMarkedText:attrString selectionRange:NSMakeRange(cursorIndex, 0) replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
NSLog(@"_handleInputStateChoosingCandidate 2");
if (_inputMode == kPlainBopomofoModeIdentifier && [state.candidates count] == 1) { if (_inputMode == kPlainBopomofoModeIdentifier && [state.candidates count] == 1) {
NSString *buffer = [self _convertToSimplifiedChineseIfRequired:state.candidates.firstObject]; NSString *buffer = [self _convertToSimplifiedChineseIfRequired:state.candidates.firstObject];
[client insertText:buffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)]; [client insertText:buffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
InputStateEmpty *empty = [[InputStateEmpty alloc] init]; InputStateEmpty *empty = [[InputStateEmpty alloc] init];
[self handleState:empty client:client]; [self handleState:empty client:client];
NSLog(@"_handleInputStateChoosingCandidate 31");
} else { } else {
NSLog(@"_handleInputStateChoosingCandidate 32");
if (![previous isKindOfClass:[InputStateChoosingCandidate class]]) { if (![previous isKindOfClass:[InputStateChoosingCandidate class]]) {
NSLog(@"_handleInputStateChoosingCandidate 33");
[self _showCandidateWindowWithState:state client:client]; [self _showCandidateWindowWithState:state client:client];
} }
} }
@ -1507,7 +1495,7 @@ static double FindHighestScore(const vector<NodeAnchor> &nodes, double epsilon)
NSLog(@"lineHeightRectangle %@", exception); NSLog(@"lineHeightRectangle %@", exception);
} }
NSLog(@"lineHeightRectangle %@", NSStringFromRect(lineHeightRect)); // NSLog(@"lineHeightRectangle %@", NSStringFromRect(lineHeightRect));
if (useVerticalMode) { if (useVerticalMode) {
[gCurrentCandidateController setWindowTopLeftPoint:NSMakePoint(lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, lineHeightRect.origin.y - 4.0) bottomOutOfScreenAdjustmentHeight:lineHeightRect.size.height + 4.0]; [gCurrentCandidateController setWindowTopLeftPoint:NSMakePoint(lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, lineHeightRect.origin.y - 4.0) bottomOutOfScreenAdjustmentHeight:lineHeightRect.size.height + 4.0];