InputHandler // Let cassette mode respond to possible final key.

This commit is contained in:
ShikiSuen 2022-10-25 09:45:02 +08:00
parent 03236671af
commit e47d5749e9
1 changed files with 14 additions and 6 deletions

View File

@ -174,16 +174,24 @@ extension InputHandler {
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
guard let delegate = delegate else { return nil }
var wildcardKey: String { currentLM.currentCassette.wildcardKey } //
let isWildcardKeyInput: Bool = (input.text == wildcardKey && !wildcardKey.isEmpty)
var keyConsumedByStrokes = false
let skipStrokeHandling =
input.isReservedKey || input.isNumericPadKey || input.isNonLaptopFunctionKey
|| input.isControlHold || input.isOptionHold || input.isShiftHold || input.isCommandHold
var isStrokesFull: Bool { calligrapher.count >= currentLM.currentCassette.maxKeyLength }
var isLongestPossibleKeyFormed: Bool {
guard !isWildcardKeyInput, !wildcardKey.isEmpty else { return false }
return !currentLM.currentCassette.hasUnigramsFor(key: calligrapher + wildcardKey) && !calligrapher.isEmpty
}
var isStrokesFull: Bool {
calligrapher.count >= currentLM.currentCassette.maxKeyLength || isLongestPossibleKeyFormed
}
prehandling: if !skipStrokeHandling && currentLM.currentCassette.allowedKeys.contains(input.text) {
if calligrapher.isEmpty, input.text == wildcardKey {
if calligrapher.isEmpty, isWildcardKeyInput {
delegate.callError("3606B9C0")
var newEmptyState = IMEState.ofEmpty()
newEmptyState.tooltip = NSLocalizedString("Wildcard key cannot be the initial key.", comment: "") + "  "
@ -195,7 +203,7 @@ extension InputHandler {
calligrapher = String(calligrapher.dropLast(1))
}
calligrapher.append(input.text)
if input.text == wildcardKey {
if isWildcardKeyInput {
break prehandling
}
keyConsumedByStrokes = true
@ -206,12 +214,12 @@ extension InputHandler {
}
}
var compoundStrokes = isStrokesFull || (input.text == wildcardKey && !calligrapher.isEmpty)
var combineStrokes = isStrokesFull || (isWildcardKeyInput && !calligrapher.isEmpty)
// Enter Space calligrapher
// |=
compoundStrokes = compoundStrokes || (!calligrapher.isEmpty && (input.isSpace || input.isEnter))
if compoundStrokes {
combineStrokes = combineStrokes || (!calligrapher.isEmpty && (input.isSpace || input.isEnter))
if combineStrokes {
//
if !currentLM.hasUnigramsFor(key: calligrapher) {
delegate.callError("B49C0979_Cassette語彙庫內無「\(calligrapher)」的匹配記錄。")