From 1e098cac5387ce2e6931878decdad2b285cae93f Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 29 Feb 2024 21:04:42 +0800 Subject: [PATCH] InputHandler // Prioritize the handling of the service menu. --- .../InputHandler_HandleCandidate.swift | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/InputHandler/InputHandler_HandleCandidate.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/InputHandler/InputHandler_HandleCandidate.swift index 5241381b..f9b61a34 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/InputHandler/InputHandler_HandleCandidate.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/InputHandler/InputHandler_HandleCandidate.swift @@ -30,6 +30,47 @@ extension InputHandler { guard ctlCandidate.visible else { return false } let inputText = ignoringModifiers ? (input.inputTextIgnoringModifiers ?? input.text) : input.text let allowMovingCompositorCursor = state.type == .ofCandidates && !prefs.useSCPCTypingMode + let highlightedCandidate = state.candidates[ctlCandidate.highlightedIndex] + + // MARK: 選字窗服務選單(Shift+?)。 + + var candidateTextServiceMenuRunning: Bool { + state.node.containsCandidateServices && state.type == .ofSymbolTable + } + + serviceMenu: if prefs.useShiftQuestionToCallServiceMenu, input.commonKeyModifierFlags == .shift, input.text == "?" { + if candidateTextServiceMenuRunning { break serviceMenu } + let handled = handleServiceMenuInitiation( + candidateText: highlightedCandidate.value, + reading: highlightedCandidate.keyArray + ) + if handled { return true } + } + + // MARK: 波浪符號鍵(選字窗服務選單 / 輔助翻頁 / 其他功能)。 + + if input.isSymbolMenuPhysicalKey { + switch input.commonKeyModifierFlags { + case .shift, [], + .option where !candidateTextServiceMenuRunning: + if !candidateTextServiceMenuRunning { + let handled = handleServiceMenuInitiation( + candidateText: highlightedCandidate.value, + reading: highlightedCandidate.keyArray + ) + if handled { return true } + } + var updated = true + let reverseTrigger = input.isShiftHold || input.isOptionHold + updated = reverseTrigger ? ctlCandidate.showPreviousLine() : ctlCandidate.showNextLine() + if !updated { delegate.callError("66F3477B") } + return true + case .option where state.type == .ofSymbolTable: + // 繞過內碼輸入模式,直接進入漢音鍵盤符號模式。 + return revolveTypingMethod(to: .haninKeyboardSymbol) + default: break + } + } // MARK: 選字窗內使用熱鍵升權、降權、刪詞。 @@ -94,7 +135,6 @@ extension InputHandler { delegate.candidateSelectionConfirmedByInputHandler(at: ctlCandidate.highlightedIndex) } - let highlightedCandidate = state.candidates[ctlCandidate.highlightedIndex] // 關聯詞語功能專用。 if let keyCodeType = KeyCode(rawValue: input.keyCode) { switch keyCodeType { case .kLineFeed, .kCarriageReturn: @@ -315,7 +355,7 @@ extension InputHandler { } } - // MARK: - Flipping pages by using modified bracket keys (when they are not occupied). + // MARK: Flipping pages by using modified bracket keys (when they are not occupied). // Shift+Command+[] 被 Chrome 系瀏覽器佔用,所以改用 Ctrl。 let ctrlCMD: Bool = input.commonKeyModifierFlags == [.control, .command] @@ -333,46 +373,6 @@ extension InputHandler { } } - // MARK: - Calling Service Menu Key through "Shift+?" (if enabled). - - var candidateTextServiceMenuRunning: Bool { - state.node.containsCandidateServices && state.type == .ofSymbolTable - } - - serviceMenu: if prefs.useShiftQuestionToCallServiceMenu, input.commonKeyModifierFlags == .shift, input.text == "?" { - if candidateTextServiceMenuRunning { break serviceMenu } - let handled = handleServiceMenuInitiation( - candidateText: highlightedCandidate.value, - reading: highlightedCandidate.keyArray - ) - if handled { return true } - } - - // MARK: - Flipping pages or Calling Service Menu by the Symbol Menu Key. - - if input.isSymbolMenuPhysicalKey { - switch input.commonKeyModifierFlags { - case .shift, [], - .option where !candidateTextServiceMenuRunning: - if !candidateTextServiceMenuRunning { - let handled = handleServiceMenuInitiation( - candidateText: highlightedCandidate.value, - reading: highlightedCandidate.keyArray - ) - if handled { return true } - } - var updated = true - let reverseTrigger = input.isShiftHold || input.isOptionHold - updated = reverseTrigger ? ctlCandidate.showPreviousLine() : ctlCandidate.showNextLine() - if !updated { delegate.callError("66F3477B") } - return true - case .option where state.type == .ofSymbolTable: - // 繞過內碼輸入模式,直接進入漢音鍵盤符號模式。 - return revolveTypingMethod(to: .haninKeyboardSymbol) - default: break - } - } - if state.type == .ofInputting { return false } // `%quick` delegate.callError("172A0F81")