diff --git a/Source/Modules/IMEState.swift b/Source/Modules/IMEState.swift index 08536c36..679d566e 100644 --- a/Source/Modules/IMEState.swift +++ b/Source/Modules/IMEState.swift @@ -69,6 +69,12 @@ extension IMEState { public static func ofDeactivated() -> IMEState { .init(type: .ofDeactivated) } public static func ofEmpty() -> IMEState { .init(type: .ofEmpty) } public static func ofAbortion() -> IMEState { .init(type: .ofAbortion) } + + /// 用以手動遞交指定內容的狀態。 + /// - Remark: 直接切換至該狀態的話,會丟失上一個狀態的內容。 + /// 如不想丟失的話,請先切換至 `.ofEmpty()` 再切換至 `.ofCommitting()`。 + /// - Parameter textToCommit: 要遞交的文本。 + /// - Returns: 要切換到的狀態。 public static func ofCommitting(textToCommit: String) -> IMEState { var result = IMEState(type: .ofCommitting) result.textToCommit = textToCommit diff --git a/Source/Modules/InputHandler_HandleInput.swift b/Source/Modules/InputHandler_HandleInput.swift index 3d253273..1aea2887 100644 --- a/Source/Modules/InputHandler_HandleInput.swift +++ b/Source/Modules/InputHandler_HandleInput.swift @@ -80,6 +80,7 @@ extension InputHandler { // 我們先規定允許小鍵盤區域操縱選字窗,其餘場合一律直接放行。 if input.isNumericPadKey { if ![.ofCandidates, .ofAssociates, .ofSymbolTable].contains(state.type) { + delegate.switchState(IMEState.ofEmpty()) delegate.switchState(IMEState.ofCommitting(textToCommit: inputText.lowercased())) return true } @@ -247,9 +248,11 @@ extension InputHandler { if input.isShiftHold { // 這裡先不要判斷 isOptionHold。 switch prefs.upperCaseLetterKeyBehavior { case 1: + delegate.switchState(IMEState.ofEmpty()) delegate.switchState(IMEState.ofCommitting(textToCommit: inputText.lowercased())) return true case 2: + delegate.switchState(IMEState.ofEmpty()) delegate.switchState(IMEState.ofCommitting(textToCommit: inputText.uppercased())) return true default: // 包括 case 0,直接塞給組字區。