Prevents the key handler to see reserved keys like page up/down as BPMF keys.

This commit is contained in:
zonble 2022-02-02 01:31:53 +08:00
parent 5afc5defdd
commit cbdbfa2518
3 changed files with 17 additions and 1 deletions

View File

@ -180,6 +180,9 @@ class McBopomofoInputMethodController: IMKInputController {
}
let input = KeyHandlerInput(event: event, isVerticalMode: useVerticalMode)
NSLog("input \(input)")
let result = keyHandler.handle(input, state: state) { newState in
self.handle(state: newState, client: client)
} candidateSelectionCallback: {

View File

@ -302,10 +302,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
}
bool composeReading = false;
BOOL skipBpmfHandling = [input isReservedKey] || [input isControlHold];
// MARK: Handle BPMF Keys
// see if it's valid BPMF reading
if (![input isControlHold] && _bpmfReadingBuffer->isValidKey((char) charCode)) {
if (!skipBpmfHandling && _bpmfReadingBuffer->isValidKey((char) charCode)) {
_bpmfReadingBuffer->combineKey((char) charCode);
// if we have a tone marker, we have to insert the reading to the

View File

@ -90,6 +90,10 @@ class KeyHandlerInput: NSObject {
super.init()
}
override var description: String {
return "<\(super.description) inputText:\(String(describing: inputText)), inputTextIgnoringModifiers:\(String(describing: inputTextIgnoringModifiers)) charCode:\(charCode), keyCode:\(keyCode), flags:\(flags), cursorForwardKey:\(cursorForwardKey), cursorBackwardKey:\(cursorBackwardKey), extraChooseCandidateKey:\(extraChooseCandidateKey), absorbedArrowKey:\(absorbedArrowKey), verticalModeOnlyChooseCandidateKey:\(verticalModeOnlyChooseCandidateKey), emacsKey:\(emacsKey), useVerticalMode:\(useVerticalMode)>"
}
@objc var isShiftHold: Bool {
flags.contains([.shift])
}
@ -118,6 +122,13 @@ class KeyHandlerInput: NSObject {
flags.contains([.numericPad])
}
@objc var isReservedKey: Bool {
guard let code = KeyCode(rawValue: keyCode) else {
return false
}
return code.rawValue != KeyCode.none.rawValue
}
@objc var isEnter: Bool {
KeyCode(rawValue: keyCode) == KeyCode.enter
}