Adds some punctuations using control key.

It allows users ever use Microsoft Bopomofo to input punctuations using
keys like ctrl + comma.
This commit is contained in:
zonble 2022-02-01 02:32:55 +08:00
parent 8573332879
commit 536c9d1fc7
2 changed files with 23 additions and 4 deletions

View File

@ -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);

View File

@ -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])
}