diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 4843438c..8d9a4279 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -167,7 +167,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // NON-SWIFTIFIABLE - (void)fixNodeWithValue:(NSString *)value { - NSInteger cursorIndex = [self _actualCandidateCursorIndex]; + NSInteger cursorIndex = [self getActualCandidateCursorIndex]; std::string stringValue(value.UTF8String); Gramambular::NodeAnchor selectedNode = _builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue); if (!mgrPrefs.useSCPCTypingMode) @@ -564,7 +564,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (!overrideValue.empty()) { - NSInteger cursorIndex = [self _actualCandidateCursorIndex]; + NSInteger cursorIndex = [self getActualCandidateCursorIndex]; std::vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); double highestScore = FindHighestScore(nodes, kEpsilon); _builder->grid().overrideNodeScoreForSelectedCandidate(cursorIndex, overrideValue, @@ -601,7 +601,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; { NSMutableArray *candidatesArray = [[NSMutableArray alloc] init]; - NSInteger cursorIndex = [self _actualCandidateCursorIndex]; + NSInteger cursorIndex = [self getActualCandidateCursorIndex]; std::vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); // sort the nodes, so that longer nodes (representing longer phrases) are placed at the top of the candidate list diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift index 08694d46..42746492 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift @@ -29,8 +29,8 @@ import Cocoa // MARK: - § Handle Candidate State. @objc extension KeyHandler { - func _handleCandidateState( - _ state: InputState, + func handleCandidate( + state: InputState, input: InputHandler, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index be9d33e7..5955d55b 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -105,16 +105,16 @@ import Cocoa // MARK: Handle Candidates. if state is InputState.ChoosingCandidate { - return _handleCandidateState( - state, input: input, stateCallback: stateCallback, errorCallback: errorCallback + return handleCandidate( + state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback ) } // MARK: Handle Associated Phrases. if state is InputState.AssociatedPhrases { - let result = _handleCandidateState( - state, input: input, stateCallback: stateCallback, errorCallback: errorCallback + let result = handleCandidate( + state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback ) if result { return true @@ -126,7 +126,7 @@ import Cocoa // MARK: Handle Marking. if let marking = state as? InputState.Marking { - if _handleMarkingState( + if handleMarkingState( marking, input: input, stateCallback: stateCallback, errorCallback: errorCallback ) { @@ -188,8 +188,8 @@ import Cocoa stateCallback(inputting) if mgrPrefs.useSCPCTypingMode { - let choosingCandidates: InputState.ChoosingCandidate = _buildCandidateState( - inputting, + let choosingCandidates: InputState.ChoosingCandidate = buildCandidate( + state: inputting, useVerticalMode: input.useVerticalMode ) if choosingCandidates.candidates.count == 1 { @@ -251,8 +251,8 @@ import Cocoa return true } } - let choosingCandidates = _buildCandidateState( - currentState, + let choosingCandidates = buildCandidate( + state: currentState, useVerticalMode: input.useVerticalMode ) stateCallback(choosingCandidates) @@ -264,13 +264,13 @@ import Cocoa // MARK: Esc - if input.isESC { return _handleEscWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) } + if input.isESC { return handleEsc(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Cursor backward if input.isCursorBackward || input.emacsKey == vChewingEmacsKey.backward { - return _handleBackwardWithState( - state, + return handleBackward( + state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback @@ -280,59 +280,59 @@ import Cocoa // MARK: Cursor forward if input.isCursorForward || input.emacsKey == vChewingEmacsKey.forward { - return _handleForwardWithState( - state, input: input, stateCallback: stateCallback, errorCallback: errorCallback + return handleForward( + state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback ) } // MARK: Home if input.isHome || input.emacsKey == vChewingEmacsKey.home { - return _handleHomeWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleHome(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: End if input.isEnd || input.emacsKey == vChewingEmacsKey.end { - return _handleEndWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleEnd(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Ctrl+PgLf or Shift+PgLf if (input.isControlHold || input.isShiftHold) && (input.isOptionHold && input.isLeft) { - return _handleHomeWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleHome(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Ctrl+PgRt or Shift+PgRt if (input.isControlHold || input.isShiftHold) && (input.isOptionHold && input.isRight) { - return _handleEndWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleEnd(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: AbsorbedArrowKey if input.isAbsorbedArrowKey || input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse { - return _handleAbsorbedArrowKeyWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleAbsorbedArrowKey(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Backspace if input.isBackSpace { - return _handleBackspaceWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleBackspace(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Delete if input.isDelete || input.emacsKey == vChewingEmacsKey.delete { - return _handleDeleteWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleDelete(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Enter if input.isEnter { return (input.isCommandHold && input.isControlHold) - ? _handleCtrlCommandEnterWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) - : _handleEnterWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + ? handleCtrlCommandEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) + : handleEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: - @@ -348,8 +348,10 @@ import Cocoa let inputting = buildInputtingState() inputting.poppedText = poppedText stateCallback(inputting) - let choosingCandidate = - _buildCandidateState(inputting, useVerticalMode: input.useVerticalMode) + let choosingCandidate = buildCandidate( + state: inputting, + useVerticalMode: input.useVerticalMode + ) stateCallback(choosingCandidate) } else { // If there is still unfinished bpmf reading, ignore the punctuation IME.prtDebugIntel("17446655") @@ -361,7 +363,7 @@ import Cocoa // 得在這裡先 commit buffer,不然會導致「在摁 ESC 離開符號選單時會重複輸入上一次的組字區的內容」的不當行為。 // 於是這裡用「模擬一次 Enter 鍵的操作」使其代為執行這個 commit buffer 的動作。 // 這裡不需要該函數所傳回的 bool 結果,所以用「_ =」解消掉。 - _ = _handleEnterWithState(state, stateCallback: stateCallback, errorCallback: errorCallback) + _ = handleEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) let root: SymbolNode! = SymbolNode.root let symbolState = InputState.SymbolTable(node: root, useVerticalMode: input.useVerticalMode) @@ -391,7 +393,7 @@ import Cocoa punctuationNamePrefix, parser, String(format: "%c", CChar(charCode)), ] let customPunctuation: String = arrCustomPunctuations.joined(separator: "") - if _handlePunctuation( + if handlePunctuation( customPunctuation, state: state, usingVerticalMode: input.useVerticalMode, @@ -405,7 +407,7 @@ import Cocoa let arrPunctuations: [String] = [punctuationNamePrefix, String(format: "%c", CChar(charCode))] let punctuation: String = arrPunctuations.joined(separator: "") - if _handlePunctuation( + if handlePunctuation( punctuation, state: state, usingVerticalMode: input.useVerticalMode, @@ -418,7 +420,7 @@ import Cocoa // 這裡不使用小麥注音 2.2 版的組字區處理方式,而是直接由詞庫負責。 if input.isUpperCaseASCIILetterKey { let letter: String! = String(format: "%@%c", "_letter_", CChar(charCode)) - if _handlePunctuation( + if handlePunctuation( letter, state: state, usingVerticalMode: input.useVerticalMode, diff --git a/Source/Modules/ControllerModules/KeyHandler_Misc.swift b/Source/Modules/ControllerModules/KeyHandler_Misc.swift index 9abf05b2..9228d065 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Misc.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Misc.swift @@ -33,7 +33,7 @@ import Cocoa mgrPrefs.mandarinParserName + "_" } - func _actualCandidateCursorIndex() -> Int { + func getActualCandidateCursorIndex() -> Int { var cursorIndex = getBuilderCursorIndex() // MS Phonetics IME style, phrase is *after* the cursor. // (i.e. the cursor is always *before* the phrase.) diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 430f3dfa..40e215f5 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -65,8 +65,8 @@ import Cocoa // MARK: - 用以生成候選詞陣列及狀態 - func _buildCandidateState( - _ currentState: InputState.NotEmpty, + func buildCandidate( + state currentState: InputState.NotEmpty, useVerticalMode: Bool ) -> InputState.ChoosingCandidate { let candidatesArray = getCandidatesArray() @@ -100,7 +100,7 @@ import Cocoa // MARK: - 用以處理就地新增自訂語彙時的行為 - func _handleMarkingState( + func handleMarkingState( _ state: InputState.Marking, input: InputHandler, stateCallback: @escaping (InputState) -> Void, @@ -186,7 +186,7 @@ import Cocoa // MARK: - 標點輸入處理 - func _handlePunctuation( + func handlePunctuation( _ customPunctuation: String, state: InputState, usingVerticalMode useVerticalMode: Bool, @@ -205,8 +205,9 @@ import Cocoa stateCallback(inputting) if mgrPrefs.useSCPCTypingMode, isPhoneticReadingBufferEmpty() { - let candidateState = _buildCandidateState( - inputting, useVerticalMode: useVerticalMode + let candidateState = buildCandidate( + state: inputting, + useVerticalMode: useVerticalMode ) if candidateState.candidates.count == 1 { clear() @@ -235,8 +236,8 @@ import Cocoa // MARK: - Enter 鍵處理 - @discardableResult func _handleEnterWithState( - _ state: InputState, + @discardableResult func handleEnter( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback _: @escaping () -> Void ) -> Bool { @@ -260,8 +261,8 @@ import Cocoa // MARK: - CMD+Enter 鍵處理 - func _handleCtrlCommandEnterWithState( - _ state: InputState, + func handleCtrlCommandEnter( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback _: @escaping () -> Void ) -> Bool { @@ -286,8 +287,8 @@ import Cocoa // MARK: - 處理 Backspace (macOS Delete) 按鍵行為 - func _handleBackspaceWithState( - _ state: InputState, + func handleBackspace( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -321,8 +322,8 @@ import Cocoa // MARK: - 處理 PC Delete (macOS Fn+BackSpace) 按鍵行為 - func _handleDeleteWithState( - _ state: InputState, + func handleDelete( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -358,8 +359,8 @@ import Cocoa // MARK: - 處理與當前文字輸入排版前後方向呈 90 度的那兩個方向鍵的按鍵行為 - func _handleAbsorbedArrowKeyWithState( - _ state: InputState, + func handleAbsorbedArrowKey( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -376,8 +377,8 @@ import Cocoa // MARK: - 處理 Home 鍵行為 - func _handleHomeWithState( - _ state: InputState, + func handleHome( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -407,8 +408,8 @@ import Cocoa // MARK: - 處理 End 鍵行為 - func _handleEndWithState( - _ state: InputState, + func handleEnd( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -438,8 +439,8 @@ import Cocoa // MARK: - 處理 Esc 鍵行為 - func _handleEscWithState( - _ state: InputState, + func handleEsc( + state: InputState, stateCallback: @escaping (InputState) -> Void, errorCallback _: @escaping () -> Void ) -> Bool { @@ -473,8 +474,8 @@ import Cocoa // MARK: - 處理向前方向鍵的行為 - func _handleForwardWithState( - _ state: InputState, + func handleForward( + state: InputState, input: InputHandler, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void @@ -525,8 +526,8 @@ import Cocoa // MARK: - 處理向後方向鍵的行為 - func _handleBackwardWithState( - _ state: InputState, + func handleBackward( + state: InputState, input: InputHandler, stateCallback: @escaping (InputState) -> Void, errorCallback: @escaping () -> Void