From 7ea221f7ec89ab585d117c07ee117da4f5dd3382 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 31 Jul 2022 21:40:19 +0800 Subject: [PATCH] KeyHandler // Suppressing EmptyIgnoringPreviousState(). --- .../KeyHandler_HandleCandidate.swift | 8 ++++--- .../KeyHandler_HandleComposition.swift | 11 +++++---- .../KeyHandler_HandleInput.swift | 2 +- .../ControllerModules/KeyHandler_States.swift | 23 +++++++++++++++---- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift index 04d31f3d..3a5e7f73 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift @@ -69,6 +69,7 @@ extension KeyHandler { // 所以這裡需要對 compositor.isEmpty 做判定。 clear() stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) } else { stateCallback(buildInputtingState) } @@ -84,6 +85,7 @@ extension KeyHandler { if state is InputState.AssociatedPhrases, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter { clear() stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) return true } delegate?.keyHandler( @@ -350,10 +352,10 @@ extension KeyHandler { ctlCandidate: ctlCandidateCurrent ) clear() - let empty = InputState.EmptyIgnoringPreviousState() - stateCallback(empty) + stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) return handle( - input: input, state: empty, stateCallback: stateCallback, errorCallback: errorCallback + input: input, state: InputState.Empty(), stateCallback: stateCallback, errorCallback: errorCallback ) } return true diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleComposition.swift b/Source/Modules/ControllerModules/KeyHandler_HandleComposition.swift index ec5b75d5..3c5d631b 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleComposition.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleComposition.swift @@ -30,18 +30,14 @@ extension KeyHandler { /// 用來處理 KeyHandler.HandleInput() 當中的與組字有關的行為。 /// - Parameters: /// - input: 輸入訊號。 - /// - state: 給定狀態(通常為當前狀態)。 /// - stateCallback: 狀態回呼,交給對應的型別內的專有函式來處理。 /// - errorCallback: 錯誤回呼。 /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 func handleComposition( input: InputSignal, - state: InputStateProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool? { - guard [.ofInputting, .ofEmpty, .ofEmptyIgnoringPreviousState].contains(state.type) else { return nil } - // MARK: 注音按鍵輸入處理 (Handle BPMF Keys) var keyConsumedByReading = false @@ -84,7 +80,12 @@ extension KeyHandler { errorCallback() composer.clear() // 根據「組字器是否為空」來判定回呼哪一種狀態。 - stateCallback((compositor.isEmpty) ? InputState.EmptyIgnoringPreviousState() : buildInputtingState) + switch compositor.isEmpty { + case false: stateCallback(buildInputtingState) + case true: + stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) + } return true // 向 IMK 報告說這個按鍵訊號已經被輸入法攔截處理了。 } diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index 073de884..0574cf46 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -159,7 +159,7 @@ extension KeyHandler { // MARK: 注音按鍵輸入處理 (Handle BPMF Keys) if let compositionHandled = handleComposition( - input: input, state: state, stateCallback: stateCallback, errorCallback: errorCallback + input: input, stateCallback: stateCallback, errorCallback: errorCallback ) { return compositionHandled } diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 8666bbfe..0410e8bd 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -419,8 +419,12 @@ extension KeyHandler { composer.doBackSpace() } - stateCallback( - composer.isEmpty && compositor.isEmpty ? InputState.EmptyIgnoringPreviousState() : buildInputtingState) + switch composer.isEmpty && compositor.isEmpty { + case false: stateCallback(buildInputtingState) + case true: + stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) + } return true } @@ -457,7 +461,12 @@ extension KeyHandler { walk() let inputting = buildInputtingState // 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。 - stateCallback(inputting.composingBuffer.isEmpty ? InputState.EmptyIgnoringPreviousState() : inputting) + switch inputting.composingBuffer.isEmpty { + case false: stateCallback(inputting) + case true: + stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) + } return true } @@ -569,11 +578,17 @@ extension KeyHandler { /// 此乃 macOS 內建注音輸入法預設之行為,但不太受 Windows 使用者群體之待見。 clear() stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) } else { if composer.isEmpty { return true } /// 如果注拼槽不是空的話,則清空之。 composer.clear() - stateCallback(compositor.isEmpty ? InputState.EmptyIgnoringPreviousState() : buildInputtingState) + switch compositor.isEmpty { + case false: stateCallback(buildInputtingState) + case true: + stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) + } } return true }