From 5c6a2078b24a4b7522dec9da43c291d45e98e475 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 30 Jun 2022 22:22:53 +0800 Subject: [PATCH] KeyHandler // Refactor handleDelete(). --- .../ControllerModules/KeyHandler_States.swift | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 219ec5f2..fc900bcb 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -473,28 +473,25 @@ extension KeyHandler { ) -> Bool { guard state is InputState.Inputting else { return false } - if composer.isEmpty { - if compositorCursorIndex != compositorLength { - deleteCompositorReadingToTheFrontOfCursor() - walk() - let inputting = buildInputtingState - // 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。 - if inputting.composingBuffer.isEmpty { - stateCallback(InputState.EmptyIgnoringPreviousState()) - } else { - stateCallback(inputting) - } - } else { - IME.prtDebugIntel("9B69938D") - errorCallback() - stateCallback(state) - } - } else { + guard composer.isEmpty else { IME.prtDebugIntel("9C69908D") errorCallback() stateCallback(state) + return true } + guard compositorCursorIndex != compositorLength else { + IME.prtDebugIntel("9B69938D") + errorCallback() + stateCallback(state) + return true + } + + deleteCompositorReadingToTheFrontOfCursor() + walk() + let inputting = buildInputtingState + // 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。 + stateCallback(inputting.composingBuffer.isEmpty ? InputState.EmptyIgnoringPreviousState() : inputting) return true }