From ab62321f7a852cf9f246648d2783cacbe90aa2c1 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 16 Jun 2022 14:46:02 +0800 Subject: [PATCH] KeyHandler // Switch candidates by Shift(+CMD)+Space. --- .../ControllerModules/KeyHandler_HandleInput.swift | 11 ++++++++--- .../Modules/ControllerModules/KeyHandler_States.swift | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index e9137323..416f0ca6 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -247,7 +247,7 @@ extension KeyHandler { { if input.isSpace { // If the Space key is NOT set to be a selection key - if input.isShiftHold || !mgrPrefs.chooseCandidateUsingSpace { + if !mgrPrefs.chooseCandidateUsingSpace { if compositorCursorIndex >= compositorLength { let composingBuffer = currentState.composingBuffer if !composingBuffer.isEmpty { @@ -264,6 +264,11 @@ extension KeyHandler { stateCallback(inputting) } return true + } else if input.isShiftHold { // 臉書等網站會攔截 Tab 鍵,所以用 Shift+CMD+Space 對候選字詞做正向/反向輪替。 + return handleInlineCandidateRotation( + state: state, reverseModifier: input.isCommandHold, stateCallback: stateCallback, + errorCallback: errorCallback + ) } } stateCallback(buildCandidate(state: currentState, isTypingVertical: input.isTypingVertical)) @@ -279,8 +284,8 @@ extension KeyHandler { // MARK: Tab if input.isTab { - return handleTab( - state: state, isShiftHold: input.isShiftHold, stateCallback: stateCallback, errorCallback: errorCallback + return handleInlineCandidateRotation( + state: state, reverseModifier: input.isShiftHold, stateCallback: stateCallback, errorCallback: errorCallback ) } diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 039772e2..715a6c31 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -642,11 +642,11 @@ extension KeyHandler { return true } - // MARK: - 處理 Tab 按鍵行為 + // MARK: - 處理上下文候選字詞輪替(Tab 按鍵,或者 Shift+Space) - func handleTab( + func handleInlineCandidateRotation( state: InputState, - isShiftHold: Bool, + reverseModifier: Bool, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -709,7 +709,7 @@ extension KeyHandler { if candidates[0] == currentValue { // If the first candidate is the value of the // current node, we use next one. - if isShiftHold { + if reverseModifier { currentIndex = candidates.count - 1 } else { currentIndex = 1 @@ -718,7 +718,7 @@ extension KeyHandler { } else { for candidate in candidates { if candidate == currentValue { - if isShiftHold { + if reverseModifier { if currentIndex == 0 { currentIndex = candidates.count - 1 } else {