From 2540b3137c2dd6d8f08200abe8f81ba83c25e652 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 9 May 2022 22:08:55 +0800 Subject: [PATCH] =?UTF-8?q?KeyHandler=20//=20Commiting=20HTML=20Ruby=20Com?= =?UTF-8?q?position=20by=20=E2=8C=98=E2=8C=83=E2=8C=A5Enter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KeyHandler_HandleInput.swift | 4 ++- .../ControllerModules/KeyHandler_States.swift | 34 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index fa95b327..57153b4d 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -341,7 +341,9 @@ extension KeyHandler { if input.isEnter { return (input.isCommandHold && input.isControlHold) - ? handleCtrlCommandEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) + ? (input.isOptionHold + ? handleCtrlOptionCommandEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) + : handleCtrlCommandEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback)) : handleEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 103e02cd..4ab80928 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -268,7 +268,7 @@ extension KeyHandler { return true } - // MARK: - CMD+Enter 鍵處理 + // MARK: - CMD+Enter 鍵處理(注音文) func handleCtrlCommandEnter( state: InputState, @@ -292,6 +292,38 @@ extension KeyHandler { return true } + // MARK: - CMD+Alt+Enter 鍵處理(網頁 Ruby 注音文標記) + + func handleCtrlOptionCommandEnter( + state: InputState, + stateCallback: @escaping (InputState) -> Void, + errorCallback _: @escaping () -> Void + ) -> Bool { + if !(state is InputState.Inputting) { + return false + } + + var composed = "" + + for theAnchor in _walkedNodes { + if let node = theAnchor.node { + let key = node.currentKeyValue().key.replacingOccurrences(of: "-", with: " ") + let value = node.currentKeyValue().value + if key.contains("_") { // 不要給標點符號等特殊元素加注音 + composed += value + } else { + composed += "\(value)(\(key))" + } + } + } + + clear() + + stateCallback(InputState.Committing(poppedText: composed)) + stateCallback(InputState.Empty()) + return true + } + // MARK: - 處理 Backspace (macOS Delete) 按鍵行為 func handleBackspace(