InputHandler // Implement wildcard key support.

- Let wildcard key function as the end key.
- Warns about incorrect wildcard key inputs.
This commit is contained in:
ShikiSuen 2022-10-19 02:10:18 +08:00
parent 2614916354
commit 9220c7f846
6 changed files with 19 additions and 2 deletions

View File

@ -170,6 +170,7 @@ extension InputHandler {
/// - Returns: IMK /// - Returns: IMK
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? { private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
guard let delegate = delegate else { return nil } guard let delegate = delegate else { return nil }
var wildcardKey: String { currentLM.currentCassette.wildcardKey } //
var keyConsumedByStrokes = false var keyConsumedByStrokes = false
let skipStrokeHandling = let skipStrokeHandling =
@ -178,11 +179,22 @@ extension InputHandler {
var isStrokesFull: Bool { calligrapher.count >= currentLM.currentCassette.maxKeyLength } var isStrokesFull: Bool { calligrapher.count >= currentLM.currentCassette.maxKeyLength }
if !skipStrokeHandling && currentLM.currentCassette.allowedKeys.contains(input.text) { prehandling: if !skipStrokeHandling && currentLM.currentCassette.allowedKeys.contains(input.text) {
if calligrapher.isEmpty, input.text == wildcardKey {
delegate.callError("3606B9C0")
var newEmptyState = IMEState.ofEmpty()
newEmptyState.tooltip = NSLocalizedString("Wildcard key cannot be the initial key.", comment: "") + "  "
newEmptyState.data.tooltipColorState = .redAlert
delegate.switchState(newEmptyState)
return true
}
if isStrokesFull { if isStrokesFull {
calligrapher = String(calligrapher.dropLast(1)) calligrapher = String(calligrapher.dropLast(1))
} }
calligrapher.append(input.text) calligrapher.append(input.text)
if input.text == wildcardKey {
break prehandling
}
keyConsumedByStrokes = true keyConsumedByStrokes = true
if !isStrokesFull { if !isStrokesFull {
@ -191,7 +203,7 @@ extension InputHandler {
} }
} }
var compoundStrokes = isStrokesFull // var compoundStrokes = isStrokesFull || (input.text == wildcardKey && !calligrapher.isEmpty)
// Enter Space calligrapher // Enter Space calligrapher
// |= // |=

View File

@ -1,4 +1,5 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key.";
"CIN Cassette Mode" = "CIN Cassette Mode"; "CIN Cassette Mode" = "CIN Cassette Mode";
"Invalid Selection Keys." = "Invalid Selection Keys."; "Invalid Selection Keys." = "Invalid Selection Keys.";
"Alphanumerical Input Mode" = "Alphanumerical Input Mode"; "Alphanumerical Input Mode" = "Alphanumerical Input Mode";

View File

@ -1,4 +1,5 @@
"vChewing" = "vChewing"; "vChewing" = "vChewing";
"Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key.";
"CIN Cassette Mode" = "CIN Cassette Mode"; "CIN Cassette Mode" = "CIN Cassette Mode";
"Invalid Selection Keys." = "Invalid Selection Keys."; "Invalid Selection Keys." = "Invalid Selection Keys.";
"Alphanumerical Input Mode" = "Alphanumerical Input Mode"; "Alphanumerical Input Mode" = "Alphanumerical Input Mode";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音入力アプリ"; "vChewing" = "威注音入力アプリ";
"Wildcard key cannot be the initial key." = "骨牌キーは最初のキーとしてはならぬ。";
"CIN Cassette Mode" = "CIN カセットモード"; "CIN Cassette Mode" = "CIN カセットモード";
"Invalid Selection Keys." = "候補用キーによる不具合。"; "Invalid Selection Keys." = "候補用キーによる不具合。";
"Alphanumerical Input Mode" = "英數入力モード"; "Alphanumerical Input Mode" = "英數入力モード";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音输入法"; "vChewing" = "威注音输入法";
"Wildcard key cannot be the initial key." = "花牌键不得作为起始码。";
"CIN Cassette Mode" = "CIN 磁带模式"; "CIN Cassette Mode" = "CIN 磁带模式";
"Invalid Selection Keys." = "选字键参数资料值不规范。"; "Invalid Selection Keys." = "选字键参数资料值不规范。";
"Alphanumerical Input Mode" = "英数输入模式"; "Alphanumerical Input Mode" = "英数输入模式";

View File

@ -1,4 +1,5 @@
"vChewing" = "威注音輸入法"; "vChewing" = "威注音輸入法";
"Wildcard key cannot be the initial key." = "花牌鍵不得作為起始碼。";
"CIN Cassette Mode" = "CIN 磁帶模式"; "CIN Cassette Mode" = "CIN 磁帶模式";
"Invalid Selection Keys." = "選字鍵參數資料值不規範。"; "Invalid Selection Keys." = "選字鍵參數資料值不規範。";
"Alphanumerical Input Mode" = "英數輸入模式"; "Alphanumerical Input Mode" = "英數輸入模式";