From 9220c7f846f5790974e73214935058391d6b793c Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 19 Oct 2022 02:10:18 +0800 Subject: [PATCH] InputHandler // Implement wildcard key support. - Let wildcard key function as the end key. - Warns about incorrect wildcard key inputs. --- .../Modules/InputHandler_HandleComposition.swift | 16 ++++++++++++++-- Source/Resources/Base.lproj/Localizable.strings | 1 + Source/Resources/en.lproj/Localizable.strings | 1 + Source/Resources/ja.lproj/Localizable.strings | 1 + .../Resources/zh-Hans.lproj/Localizable.strings | 1 + .../Resources/zh-Hant.lproj/Localizable.strings | 1 + 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index e8c31cbe..a98f5c7f 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -170,6 +170,7 @@ extension InputHandler { /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? { guard let delegate = delegate else { return nil } + var wildcardKey: String { currentLM.currentCassette.wildcardKey } // 花牌鍵。 var keyConsumedByStrokes = false let skipStrokeHandling = @@ -178,11 +179,22 @@ extension InputHandler { 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 { calligrapher = String(calligrapher.dropLast(1)) } calligrapher.append(input.text) + if input.text == wildcardKey { + break prehandling + } keyConsumedByStrokes = true if !isStrokesFull { @@ -191,7 +203,7 @@ extension InputHandler { } } - var compoundStrokes = isStrokesFull // 這裡不需要做排他性判斷。 + var compoundStrokes = isStrokesFull || (input.text == wildcardKey && !calligrapher.isEmpty) // 如果當前的按鍵是 Enter 或 Space 的話,這時就可以取出 calligrapher 內的筆畫來做檢查了。 // 來看看詞庫內到底有沒有對應的讀音索引。這裡用了類似「|=」的判斷處理方式。 diff --git a/Source/Resources/Base.lproj/Localizable.strings b/Source/Resources/Base.lproj/Localizable.strings index c59ebc17..c9e1d775 100644 --- a/Source/Resources/Base.lproj/Localizable.strings +++ b/Source/Resources/Base.lproj/Localizable.strings @@ -1,4 +1,5 @@ "vChewing" = "vChewing"; +"Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key."; "CIN Cassette Mode" = "CIN Cassette Mode"; "Invalid Selection Keys." = "Invalid Selection Keys."; "Alphanumerical Input Mode" = "Alphanumerical Input Mode"; diff --git a/Source/Resources/en.lproj/Localizable.strings b/Source/Resources/en.lproj/Localizable.strings index c59ebc17..c9e1d775 100644 --- a/Source/Resources/en.lproj/Localizable.strings +++ b/Source/Resources/en.lproj/Localizable.strings @@ -1,4 +1,5 @@ "vChewing" = "vChewing"; +"Wildcard key cannot be the initial key." = "Wildcard key cannot be the initial key."; "CIN Cassette Mode" = "CIN Cassette Mode"; "Invalid Selection Keys." = "Invalid Selection Keys."; "Alphanumerical Input Mode" = "Alphanumerical Input Mode"; diff --git a/Source/Resources/ja.lproj/Localizable.strings b/Source/Resources/ja.lproj/Localizable.strings index ebd99631..c0ab375f 100644 --- a/Source/Resources/ja.lproj/Localizable.strings +++ b/Source/Resources/ja.lproj/Localizable.strings @@ -1,4 +1,5 @@ "vChewing" = "威注音入力アプリ"; +"Wildcard key cannot be the initial key." = "骨牌キーは最初のキーとしてはならぬ。"; "CIN Cassette Mode" = "CIN カセットモード"; "Invalid Selection Keys." = "候補用キーによる不具合。"; "Alphanumerical Input Mode" = "英數入力モード"; diff --git a/Source/Resources/zh-Hans.lproj/Localizable.strings b/Source/Resources/zh-Hans.lproj/Localizable.strings index 1ef65fe2..70502231 100644 --- a/Source/Resources/zh-Hans.lproj/Localizable.strings +++ b/Source/Resources/zh-Hans.lproj/Localizable.strings @@ -1,4 +1,5 @@ "vChewing" = "威注音输入法"; +"Wildcard key cannot be the initial key." = "花牌键不得作为起始码。"; "CIN Cassette Mode" = "CIN 磁带模式"; "Invalid Selection Keys." = "选字键参数资料值不规范。"; "Alphanumerical Input Mode" = "英数输入模式"; diff --git a/Source/Resources/zh-Hant.lproj/Localizable.strings b/Source/Resources/zh-Hant.lproj/Localizable.strings index 51aceea8..9a060628 100644 --- a/Source/Resources/zh-Hant.lproj/Localizable.strings +++ b/Source/Resources/zh-Hant.lproj/Localizable.strings @@ -1,4 +1,5 @@ "vChewing" = "威注音輸入法"; +"Wildcard key cannot be the initial key." = "花牌鍵不得作為起始碼。"; "CIN Cassette Mode" = "CIN 磁帶模式"; "Invalid Selection Keys." = "選字鍵參數資料值不規範。"; "Alphanumerical Input Mode" = "英數輸入模式";