From 536c9d1fc70c3510c66e7d083f78afd94cdeef20 Mon Sep 17 00:00:00 2001 From: zonble Date: Tue, 1 Feb 2022 02:32:55 +0800 Subject: [PATCH] Adds some punctuations using control key. It allows users ever use Microsoft Bopomofo to input punctuations using keys like ctrl + comma. --- Source/KeyHandler.mm | 23 +++++++++++++++++++---- Source/KeyHandlerInput.swift | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index 44d53e05..05ce0323 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -231,7 +231,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot } // if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it - BOOL isFunctionKey = ([input isCommandHold] || [input isControlHold] || [input isOptionHold] || [input isNumericPad]); + BOOL isFunctionKey = ([input isCommandHold] || [input isOptionHold] || [input isNumericPad]) || [input isControlHotKey]; if (![state isKindOfClass:[InputStateNotEmpty class]] && ![state isKindOfClass:[InputStateAssociatedPhrases class]] && isFunctionKey) { @@ -305,7 +305,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot // MARK: Handle BPMF Keys // see if it's valid BPMF reading - if (_bpmfReadingBuffer->isValidKey((char) charCode)) { + if (![input isControlHold] && _bpmfReadingBuffer->isValidKey((char) charCode)) { _bpmfReadingBuffer->combineKey((char) charCode); // if we have a tone marker, we have to insert the reading to the @@ -490,8 +490,16 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot // MARK: Punctuation // if nothing is matched, see if it's a punctuation key for current layout. + + string punctuationNamePrefix; + if ([input isControlHold]) { + punctuationNamePrefix = string("_ctrl_punctuation_"); + } else if (Preferences.halfWidthPunctuationEnabled) { + punctuationNamePrefix = string("_half_punctuation_"); + } else { + punctuationNamePrefix = string("_punctuation_"); + } string layout = [self _currentLayout]; - string punctuationNamePrefix = Preferences.halfWidthPunctuationEnabled ? string("_half_punctuation_") : string("_punctuation_"); string customPunctuation = punctuationNamePrefix + layout + string(1, (char) charCode); if ([self _handlePunctuation:customPunctuation state:state usingVerticalMode:input.useVerticalMode stateCallback:stateCallback errorCallback:errorCallback]) { return YES; @@ -1070,7 +1078,14 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot if (_inputMode == InputModePlainBopomofo) { string layout = [self _currentLayout]; - string punctuationNamePrefix = Preferences.halfWidthPunctuationEnabled ? string("_half_punctuation_") : string("_punctuation_"); + string punctuationNamePrefix; + if ([input isControlHold]) { + punctuationNamePrefix = string("_ctrl_punctuation_"); + } else if (Preferences.halfWidthPunctuationEnabled) { + punctuationNamePrefix = string("_half_punctuation_"); + } else { + punctuationNamePrefix = string("_punctuation_"); + } string customPunctuation = punctuationNamePrefix + layout + string(1, (char) charCode); string punctuation = punctuationNamePrefix + string(1, (char) charCode); diff --git a/Source/KeyHandlerInput.swift b/Source/KeyHandlerInput.swift index ad86c1b2..ad8c5bb9 100644 --- a/Source/KeyHandlerInput.swift +++ b/Source/KeyHandlerInput.swift @@ -102,6 +102,10 @@ class KeyHandlerInput: NSObject { flags.contains([.control]) } + @objc var isControlHotKey: Bool { + flags.contains([.control]) && inputText?.first?.isLetter ?? false + } + @objc var isOptionHold: Bool { flags.contains([.option]) }