KeyHandler // Simplifying the Enter-key Conditioning.

This commit is contained in:
ShikiSuen 2022-02-23 14:24:20 +08:00
parent 489385ae2b
commit 5fa40b5b42
2 changed files with 6 additions and 10 deletions

View File

@ -263,7 +263,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
}
// Caps Lock processing : if Caps Lock is on, temporarily disable bopomofo.
if ([input isBackSpace] || [input isEnterCharCode] || [input isEnter] || [input isAbsorbedArrowKey] || [input isExtraChooseCandidateKey] || [input isExtraChooseCandidateKeyReverse] || [input isCursorForward] || [input isCursorBackward]) {
if ([input isBackSpace] || [input isEnter] || [input isAbsorbedArrowKey] || [input isExtraChooseCandidateKey] || [input isExtraChooseCandidateKeyReverse] || [input isCursorForward] || [input isCursorBackward]) {
// do nothing if backspace is pressed -- we ignore the key
} else if ([input isCapsLockOn]) {
// process all possible combination, we hope.
@ -347,7 +347,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// see if we have composition if Enter/Space is hit and buffer is not empty
// this is bit-OR'ed so that the tone marker key is also taken into account
composeReading |= (!_bpmfReadingBuffer->isEmpty() && ([input isSpace] || [input isEnterCharCode] || [input isEnter]));
composeReading |= (!_bpmfReadingBuffer->isEmpty() && ([input isSpace] || [input isEnter]));
if (composeReading) {
// combine the reading
std::string reading = _bpmfReadingBuffer->syllable().composedString();
@ -506,7 +506,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
}
// MARK: Enter
if ([input isEnter] || [input isEnterCharCode]) {
if ([input isEnter]) {
if ([input isControlHold]) {
if (ctlInputMethod.areWeUsingOurOwnPhraseEditor) {
return [self _handleCtrlEnterWithState:state stateCallback:stateCallback errorCallback:errorCallback];
@ -918,7 +918,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
}
// Enter
if ([input isEnter] || [input isEnterCharCode]) {
if ([input isEnter]) {
if (![self.delegate keyHandler:self didRequestWriteUserPhraseWithState:state]) {
[self errorCallbackConsolePrint:@"5B69CC8D"];
errorCallback();
@ -1013,7 +1013,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
return YES;
}
if ([input isEnterCharCode] || [input isEnter]) {
if ([input isEnter]) {
if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
[self clear];
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];

View File

@ -144,11 +144,7 @@ class KeyHandlerInput: NSObject {
}
@objc var isEnter: Bool {
KeyCode(rawValue: keyCode) == KeyCode.enter
}
@objc var isEnterCharCode: Bool {
CharCode(rawValue: charCode) == CharCode.enter
(CharCode(rawValue: charCode) == CharCode.enter) || (KeyCode(rawValue: keyCode) == KeyCode.enter)
}
@objc var isUp: Bool {