diff --git a/Source/Modules/ControllerModules/InputSignal.swift b/Source/Modules/ControllerModules/InputSignal.swift index c972f704..a6f6a423 100644 --- a/Source/Modules/ControllerModules/InputSignal.swift +++ b/Source/Modules/ControllerModules/InputSignal.swift @@ -121,7 +121,7 @@ enum CharCode: UInt16 { } struct InputSignal: CustomStringConvertible { - private(set) var useVerticalMode: Bool + private(set) var isTypingVertical: Bool private(set) var inputText: String? private(set) var inputTextIgnoringModifiers: String? private(set) var charCode: UInt16 @@ -133,12 +133,12 @@ struct InputSignal: CustomStringConvertible { private var extraChooseCandidateKey: KeyCode = .kNone private var extraChooseCandidateKeyReverse: KeyCode = .kNone private var absorbedArrowKey: KeyCode = .kNone - private var verticalModeOnlyChooseCandidateKey: KeyCode = .kNone + private var verticalTypingOnlyChooseCandidateKey: KeyCode = .kNone private(set) var emacsKey: vChewingEmacsKey public init( inputText: String?, keyCode: UInt16, charCode: UInt16, flags: NSEvent.ModifierFlags, - isVerticalMode: Bool, inputTextIgnoringModifiers: String? = nil + isVerticalTyping: Bool, inputTextIgnoringModifiers: String? = nil ) { let inputText = AppleKeyboardConverter.cnvStringApple2ABC(inputText ?? "") let inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC( @@ -147,7 +147,7 @@ struct InputSignal: CustomStringConvertible { self.inputTextIgnoringModifiers = inputTextIgnoringModifiers self.flags = flags isFlagChanged = false - useVerticalMode = isVerticalMode + isTypingVertical = isVerticalTyping self.keyCode = keyCode self.charCode = AppleKeyboardConverter.cnvApple2ABC(charCode) emacsKey = EmacsKeyHelper.detect( @@ -157,14 +157,14 @@ struct InputSignal: CustomStringConvertible { defineArrowKeys() } - public init(event: NSEvent, isVerticalMode: Bool) { + public init(event: NSEvent, isVerticalTyping: Bool) { inputText = AppleKeyboardConverter.cnvStringApple2ABC(event.characters ?? "") inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC( event.charactersIgnoringModifiers ?? "") keyCode = event.keyCode flags = event.modifierFlags isFlagChanged = (event.type == .flagsChanged) ? true : false - useVerticalMode = isVerticalMode + isTypingVertical = isVerticalTyping let charCode: UInt16 = { // 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。 guard let inputText = event.characters, !inputText.isEmpty else { @@ -182,16 +182,16 @@ struct InputSignal: CustomStringConvertible { } mutating func defineArrowKeys() { - cursorForwardKey = useVerticalMode ? .kDownArrow : .kRightArrow - cursorBackwardKey = useVerticalMode ? .kUpArrow : .kLeftArrow - extraChooseCandidateKey = useVerticalMode ? .kLeftArrow : .kDownArrow - extraChooseCandidateKeyReverse = useVerticalMode ? .kRightArrow : .kUpArrow - absorbedArrowKey = useVerticalMode ? .kRightArrow : .kUpArrow - verticalModeOnlyChooseCandidateKey = useVerticalMode ? absorbedArrowKey : .kNone + cursorForwardKey = isTypingVertical ? .kDownArrow : .kRightArrow + cursorBackwardKey = isTypingVertical ? .kUpArrow : .kLeftArrow + extraChooseCandidateKey = isTypingVertical ? .kLeftArrow : .kDownArrow + extraChooseCandidateKeyReverse = isTypingVertical ? .kRightArrow : .kUpArrow + absorbedArrowKey = isTypingVertical ? .kRightArrow : .kUpArrow + verticalTypingOnlyChooseCandidateKey = isTypingVertical ? absorbedArrowKey : .kNone } var description: String { - "" + "" } // 除了 ANSI charCode 以外,其餘一律過濾掉,免得純 Swift 版 KeyHandler 被餵屎。 @@ -334,8 +334,8 @@ struct InputSignal: CustomStringConvertible { KeyCode(rawValue: keyCode) == extraChooseCandidateKeyReverse } - var isVerticalModeOnlyChooseCandidateKey: Bool { - KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey + var isverticalTypingOnlyChooseCandidateKey: Bool { + KeyCode(rawValue: keyCode) == verticalTypingOnlyChooseCandidateKey } var isUpperCaseASCIILetterKey: Bool { diff --git a/Source/Modules/ControllerModules/InputState.swift b/Source/Modules/ControllerModules/InputState.swift index afdc0a46..65286924 100644 --- a/Source/Modules/ControllerModules/InputState.swift +++ b/Source/Modules/ControllerModules/InputState.swift @@ -317,11 +317,11 @@ class InputState { /// Represents that the user is choosing in a candidates list. class ChoosingCandidate: NotEmpty { private(set) var candidates: [String] - private(set) var useVerticalMode: Bool + private(set) var isTypingVertical: Bool - init(composingBuffer: String, cursorIndex: Int, candidates: [String], useVerticalMode: Bool) { + init(composingBuffer: String, cursorIndex: Int, candidates: [String], isTypingVertical: Bool) { self.candidates = candidates - self.useVerticalMode = useVerticalMode + self.isTypingVertical = isTypingVertical super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex) } @@ -337,7 +337,7 @@ class InputState { } override var description: String { - "" + "" } } @@ -347,27 +347,27 @@ class InputState { /// in the associated phrases mode. class AssociatedPhrases: InputState { private(set) var candidates: [String] = [] - private(set) var useVerticalMode: Bool = false - init(candidates: [String], useVerticalMode: Bool) { + private(set) var isTypingVertical: Bool = false + init(candidates: [String], isTypingVertical: Bool) { self.candidates = candidates - self.useVerticalMode = useVerticalMode + self.isTypingVertical = isTypingVertical super.init() } var description: String { - "" + "" } } class SymbolTable: ChoosingCandidate { var node: SymbolNode - init(node: SymbolNode, useVerticalMode: Bool) { + init(node: SymbolNode, isTypingVertical: Bool) { self.node = node let candidates = node.children?.map(\.title) ?? [String]() super.init( composingBuffer: "", cursorIndex: 0, candidates: candidates, - useVerticalMode: useVerticalMode + isTypingVertical: isTypingVertical ) } @@ -388,7 +388,7 @@ class InputState { } override var description: String { - "" + "" } } } diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index acb9633f..5e51dad9 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -200,7 +200,7 @@ extension KeyHandler { if mgrPrefs.useSCPCTypingMode { let choosingCandidates: InputState.ChoosingCandidate = buildCandidate( state: inputting, - useVerticalMode: input.useVerticalMode + isTypingVertical: input.isTypingVertical ) if choosingCandidates.candidates.count == 1 { clear() @@ -213,7 +213,7 @@ extension KeyHandler { if let associatedPhrases = buildAssociatePhraseState( withKey: text, - useVerticalMode: input.useVerticalMode + isTypingVertical: input.isTypingVertical ), !associatedPhrases.candidates.isEmpty { stateCallback(associatedPhrases) @@ -243,7 +243,7 @@ extension KeyHandler { if let currentState = state as? InputState.NotEmpty, _composer.isEmpty, input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse || input.isSpace || input.isPageDown || input.isPageUp || (input.isTab && mgrPrefs.specifyShiftTabKeyBehavior) - || (input.useVerticalMode && (input.isVerticalModeOnlyChooseCandidateKey)) + || (input.isTypingVertical && (input.isverticalTypingOnlyChooseCandidateKey)) { if input.isSpace { // If the Space key is NOT set to be a selection key @@ -266,7 +266,7 @@ extension KeyHandler { return true } } - stateCallback(buildCandidate(state: currentState, useVerticalMode: input.useVerticalMode)) + stateCallback(buildCandidate(state: currentState, isTypingVertical: input.isTypingVertical)) return true } @@ -368,7 +368,7 @@ extension KeyHandler { let inputting = buildInputtingState inputting.poppedText = poppedText stateCallback(inputting) - stateCallback(buildCandidate(state: inputting, useVerticalMode: input.useVerticalMode)) + stateCallback(buildCandidate(state: inputting, isTypingVertical: input.isTypingVertical)) } else { // If there is still unfinished bpmf reading, ignore the punctuation IME.prtDebugIntel("17446655") errorCallback() @@ -380,7 +380,7 @@ extension KeyHandler { // 於是這裡用「模擬一次 Enter 鍵的操作」使其代為執行這個 commit buffer 的動作。 // 這裡不需要該函數所傳回的 bool 結果,所以用「_ =」解消掉。 _ = handleEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) - stateCallback(InputState.SymbolTable(node: SymbolNode.root, useVerticalMode: input.useVerticalMode)) + stateCallback(InputState.SymbolTable(node: SymbolNode.root, isTypingVertical: input.isTypingVertical)) return true } } @@ -411,7 +411,7 @@ extension KeyHandler { if handlePunctuation( customPunctuation, state: state, - usingVerticalMode: input.useVerticalMode, + usingVerticalTyping: input.isTypingVertical, stateCallback: stateCallback, errorCallback: errorCallback ) { @@ -425,7 +425,7 @@ extension KeyHandler { if handlePunctuation( punctuation, state: state, - usingVerticalMode: input.useVerticalMode, + usingVerticalTyping: input.isTypingVertical, stateCallback: stateCallback, errorCallback: errorCallback ) { @@ -438,7 +438,7 @@ extension KeyHandler { if handlePunctuation( letter, state: state, - usingVerticalMode: input.useVerticalMode, + usingVerticalTyping: input.isTypingVertical, stateCallback: stateCallback, errorCallback: errorCallback ) { diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 2c4ea14a..6c516dbc 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -147,13 +147,13 @@ extension KeyHandler { func buildCandidate( state currentState: InputState.NotEmpty, - useVerticalMode: Bool = false + isTypingVertical: Bool = false ) -> InputState.ChoosingCandidate { InputState.ChoosingCandidate( composingBuffer: currentState.composingBuffer, cursorIndex: currentState.cursorIndex, candidates: candidatesArray, - useVerticalMode: useVerticalMode + isTypingVertical: isTypingVertical ) } @@ -168,11 +168,11 @@ extension KeyHandler { // 是否為空:如果陣列為空的話,直接回呼一個空狀態。 func buildAssociatePhraseState( withKey key: String!, - useVerticalMode: Bool + isTypingVertical: Bool ) -> InputState.AssociatedPhrases! { // 上一行必須要用驚嘆號,否則 Xcode 會誤導你砍掉某些實際上必需的語句。 InputState.AssociatedPhrases( - candidates: buildAssociatePhraseArray(withKey: key), useVerticalMode: useVerticalMode + candidates: buildAssociatePhraseArray(withKey: key), isTypingVertical: isTypingVertical ) } @@ -251,7 +251,7 @@ extension KeyHandler { func handlePunctuation( _ customPunctuation: String, state: InputState, - usingVerticalMode useVerticalMode: Bool, + usingVerticalTyping isTypingVertical: Bool, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -269,7 +269,7 @@ extension KeyHandler { if mgrPrefs.useSCPCTypingMode, _composer.isEmpty { let candidateState = buildCandidate( state: inputting, - useVerticalMode: useVerticalMode + isTypingVertical: isTypingVertical ) if candidateState.candidates.count == 1 { clear() diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index edd0a42e..d84cf7c2 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -168,7 +168,7 @@ class ctlInputMethod: IMKInputController { forCharacterIndex: 0, lineHeightRectangle: &textFrame ) - let useVerticalMode = + let isTypingVertical = (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false if client.bundleIdentifier() @@ -179,7 +179,7 @@ class ctlInputMethod: IMKInputController { IME.areWeUsingOurOwnPhraseEditor = false } - let input = InputSignal(event: event, isVerticalMode: useVerticalMode) + let input = InputSignal(event: event, isVerticalTyping: isTypingVertical) // 無法列印的訊號輸入,一概不作處理。 // 這個過程不能放在 KeyHandler 內,否則不會起作用。 @@ -457,17 +457,17 @@ extension ctlInputMethod { extension ctlInputMethod { private func show(candidateWindowWith state: InputState, client: Any!) { - var useVerticalMode: Bool { - var useVerticalMode = false + var isTypingVertical: Bool { + var isTypingVertical = false var candidates: [String] = [] if let state = state as? InputState.ChoosingCandidate { - useVerticalMode = state.useVerticalMode + isTypingVertical = state.isTypingVertical candidates = state.candidates } else if let state = state as? InputState.AssociatedPhrases { - useVerticalMode = state.useVerticalMode + isTypingVertical = state.isTypingVertical candidates = state.candidates } - if useVerticalMode { return true } + if isTypingVertical { return true } candidates.sort { $0.count > $1.count } @@ -481,7 +481,7 @@ extension ctlInputMethod { ctlCandidateCurrent.delegate = nil - if useVerticalMode { + if isTypingVertical { ctlCandidateCurrent.currentLayout = .vertical } else if mgrPrefs.useHorizontalCandidateList { ctlCandidateCurrent.currentLayout = .horizontal @@ -552,7 +552,7 @@ extension ctlInputMethod { cursor -= 1 } - if useVerticalMode { + if isTypingVertical { ctlCandidateCurrent.set( windowTopLeftPoint: NSPoint( x: lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, y: lineHeightRect.origin.y - 4.0 @@ -662,7 +662,7 @@ extension ctlInputMethod: ctlCandidateDelegate { { if let children = node.children, !children.isEmpty { handle( - state: .SymbolTable(node: node, useVerticalMode: state.useVerticalMode), + state: .SymbolTable(node: node, isTypingVertical: state.isTypingVertical), client: currentClient ) } else { @@ -684,7 +684,7 @@ extension ctlInputMethod: ctlCandidateDelegate { handle(state: .Committing(poppedText: composingBuffer), client: client) if mgrPrefs.associatedPhrasesEnabled, let associatePhrases = keyHandler.buildAssociatePhraseState( - withKey: composingBuffer, useVerticalMode: state.useVerticalMode + withKey: composingBuffer, isTypingVertical: state.isTypingVertical ), !associatePhrases.candidates.isEmpty { handle(state: associatePhrases, client: client) @@ -702,7 +702,7 @@ extension ctlInputMethod: ctlCandidateDelegate { handle(state: .Committing(poppedText: selectedValue), client: currentClient) if mgrPrefs.associatedPhrasesEnabled, let associatePhrases = keyHandler.buildAssociatePhraseState( - withKey: selectedValue, useVerticalMode: state.useVerticalMode + withKey: selectedValue, isTypingVertical: state.isTypingVertical ), !associatePhrases.candidates.isEmpty { handle(state: associatePhrases, client: client)