From cbdbfa251840a00eb27ddb3ff714d8d9bc05abb4 Mon Sep 17 00:00:00 2001 From: zonble Date: Wed, 2 Feb 2022 01:31:53 +0800 Subject: [PATCH] Prevents the key handler to see reserved keys like page up/down as BPMF keys. --- Source/InputMethodController.swift | 3 +++ Source/KeyHandler.mm | 4 +++- Source/KeyHandlerInput.swift | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/InputMethodController.swift b/Source/InputMethodController.swift index d8d3591a..cd8c108c 100644 --- a/Source/InputMethodController.swift +++ b/Source/InputMethodController.swift @@ -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: { diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index 3bd713d1..569eca31 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -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 diff --git a/Source/KeyHandlerInput.swift b/Source/KeyHandlerInput.swift index ad8c5bb9..2e4fbfa7 100644 --- a/Source/KeyHandlerInput.swift +++ b/Source/KeyHandlerInput.swift @@ -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 }