From 79b3651ad4e29620b6570daeb3db431f0379ca55 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 23 Aug 2022 11:36:37 +0800 Subject: [PATCH] KeyHandler // Redefine how Shift+BackSpace behaves. * Also implement Shift+Option+BackSpace. --- .../ControllerModules/KeyHandler_States.swift | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 0c1166dc..12c61d76 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -409,7 +409,25 @@ extension KeyHandler { ) -> Bool { guard state is InputState.Inputting else { return false } - if input.isShiftHold { + // 引入 macOS 內建注音輸入法的行為,允許用 Shift+BackSpace 解構前一個漢字的讀音。 + switch mgrPrefs.specifyShiftBackSpaceKeyBehavior { + case 0: + guard input.isShiftHold, composer.isEmpty else { break } + guard let prevReading = previousParsableReading else { break } + // prevReading 的內容分別是:「完整讀音」「去掉聲調的讀音」「是否有聲調」。 + compositor.dropKey(direction: .rear) + walk() // 這裡必須 Walk 一次、來更新目前被 walk 的內容。 + prevReading.1.charComponents.forEach { composer.receiveKey(fromPhonabet: $0) } + stateCallback(buildInputtingState) + return true + case 1: + stateCallback(InputState.EmptyIgnoringPreviousState()) + stateCallback(InputState.Empty()) + return true + default: break + } + + if input.isShiftHold, input.isOptionHold { stateCallback(InputState.EmptyIgnoringPreviousState()) stateCallback(InputState.Empty()) return true