diff --git a/Packages/OpenVanilla_Voltaire/Sources/Voltaire/CtlCandidateUniversal.swift b/Packages/OpenVanilla_Voltaire/Sources/Voltaire/CtlCandidateUniversal.swift index ae5b6ddc..858d215f 100644 --- a/Packages/OpenVanilla_Voltaire/Sources/Voltaire/CtlCandidateUniversal.swift +++ b/Packages/OpenVanilla_Voltaire/Sources/Voltaire/CtlCandidateUniversal.swift @@ -433,7 +433,7 @@ public class CtlCandidateUniversal: CtlCandidate { @discardableResult override public func highlightNextCandidate() -> Bool { guard let delegate = delegate else { return false } selectedCandidateIndex = - (selectedCandidateIndex + 1 >= delegate.candidateCountForController(self)) + (selectedCandidateIndex + 1 >= delegate.candidatePairs().count) ? 0 : selectedCandidateIndex + 1 return true } @@ -442,7 +442,7 @@ public class CtlCandidateUniversal: CtlCandidate { guard let delegate = delegate else { return false } selectedCandidateIndex = (selectedCandidateIndex == 0) - ? delegate.candidateCountForController(self) - 1 : selectedCandidateIndex - 1 + ? delegate.candidatePairs().count - 1 : selectedCandidateIndex - 1 return true } @@ -452,7 +452,7 @@ public class CtlCandidateUniversal: CtlCandidate { } let result = currentPageIndex * keyLabels.count + index - return result < delegate.candidateCountForController(self) ? result : Int.max + return result < delegate.candidatePairs().count ? result : Int.max } override public var selectedCandidateIndex: Int { @@ -464,7 +464,7 @@ public class CtlCandidateUniversal: CtlCandidate { return } let keyLabelCount = keyLabels.count - if newValue < delegate.candidateCountForController(self) { + if newValue < delegate.candidatePairs().count { currentPageIndex = newValue / keyLabelCount candidateView.highlightedIndex = newValue % keyLabelCount layoutCandidateView() @@ -478,7 +478,7 @@ extension CtlCandidateUniversal { guard let delegate = delegate else { return 0 } - let totalCount = delegate.candidateCountForController(self) + let totalCount = delegate.candidatePairs().count let keyLabelCount = keyLabels.count return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0) } @@ -487,7 +487,7 @@ extension CtlCandidateUniversal { guard let delegate = delegate else { return 0 } - let totalCount = delegate.candidateCountForController(self) + let totalCount = delegate.candidatePairs().count let keyLabelCount = keyLabels.count return totalCount % keyLabelCount } @@ -497,12 +497,12 @@ extension CtlCandidateUniversal { candidateView.set(keyLabelFont: keyLabelFont, candidateFont: candidateFont) var candidates = [(String, String)]() - let count = delegate.candidateCountForController(self) + let count = delegate.candidatePairs().count let keyLabelCount = keyLabels.count let begin = currentPageIndex * keyLabelCount for index in begin.. Int - func candidatesForController(_ controller: CtlCandidateProtocol) -> [(String, String)] - func ctlCandidate(_ controller: CtlCandidateProtocol, candidateAtIndex index: Int) - -> (String, String) - func candidateSelected(at index: Int) + func candidatePairs() -> [(String, String)] + func candidatePairAt(_ index: Int) -> (String, String) + func candidatePairSelected(at index: Int) func buzz() func kanjiConversionIfRequired(_ target: String) -> String } diff --git a/Source/Modules/KeyHandler_Core.swift b/Source/Modules/KeyHandler_Core.swift index f4788c1d..4145ba92 100644 --- a/Source/Modules/KeyHandler_Core.swift +++ b/Source/Modules/KeyHandler_Core.swift @@ -20,7 +20,7 @@ import Tekkon /// KeyHandler 委任協定 public protocol KeyHandlerDelegate { var clientBundleIdentifier: String { get } - func ctlCandidate() -> CtlCandidateProtocol + func candidateController() -> CtlCandidateProtocol func candidateSelectionCalledByKeyHandler(at index: Int) func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool) -> Bool diff --git a/Source/Modules/KeyHandler_HandleCandidate.swift b/Source/Modules/KeyHandler_HandleCandidate.swift index 86671c68..b449d2bc 100644 --- a/Source/Modules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/KeyHandler_HandleCandidate.swift @@ -26,7 +26,7 @@ extension KeyHandler { stateCallback: @escaping (IMEStateProtocol) -> Void, errorCallback: @escaping (String) -> Void ) -> Bool { - guard var ctlCandidate = delegate?.ctlCandidate() else { + guard var ctlCandidate = delegate?.candidateController() else { errorCallback("06661F6E") return true } diff --git a/Source/Modules/SessionCtl_Delegates.swift b/Source/Modules/SessionCtl_Delegates.swift index fa67af69..66ad9022 100644 --- a/Source/Modules/SessionCtl_Delegates.swift +++ b/Source/Modules/SessionCtl_Delegates.swift @@ -18,25 +18,23 @@ extension SessionCtl: KeyHandlerDelegate { return client.bundleIdentifier() ?? "" } - func ctlCandidate() -> CtlCandidateProtocol { Self.ctlCandidateCurrent } + func candidateController() -> CtlCandidateProtocol { Self.ctlCandidateCurrent } func candidateSelectionCalledByKeyHandler(at index: Int) { - candidateSelected(at: index) + candidatePairSelected(at: index) } func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool) -> Bool { guard state.type == .ofMarking else { return false } - let refInputModeReversed: Shared.InputMode = - (inputMode == .imeModeCHT) ? .imeModeCHS : .imeModeCHT if !LMMgr.writeUserPhrase( state.data.userPhraseDumped, inputMode: inputMode, areWeDuplicating: state.data.doesUserPhraseExist, areWeDeleting: addToFilter ) || !LMMgr.writeUserPhrase( - state.data.userPhraseDumpedConverted, inputMode: refInputModeReversed, + state.data.userPhraseDumpedConverted, inputMode: inputMode.reversed, areWeDuplicating: false, areWeDeleting: addToFilter ) @@ -58,36 +56,18 @@ extension SessionCtl: CtlCandidateDelegate { ChineseConverter.kanjiConversionIfRequired(target) } - func candidateCountForController(_ controller: CtlCandidateProtocol) -> Int { - _ = controller // 防止格式整理工具毀掉與此對應的參數。 - if state.isCandidateContainer { - return state.candidates.count - } - return 0 + func candidatePairs() -> [(String, String)] { + state.isCandidateContainer ? state.candidates : [] } - /// 直接給出全部的候選字詞的字音配對陣列 - /// - Parameter controller: 對應的控制器。因為有唯一解,所以填錯了也不會有影響。 - /// - Returns: 候選字詞陣列(字音配對)。 - func candidatesForController(_ controller: CtlCandidateProtocol) -> [(String, String)] { - _ = controller // 防止格式整理工具毀掉與此對應的參數。 - if state.isCandidateContainer { - return state.candidates - } - return .init() - } - - func ctlCandidate(_ controller: CtlCandidateProtocol, candidateAtIndex index: Int) - -> (String, String) - { - _ = controller // 防止格式整理工具毀掉與此對應的參數。 - if state.isCandidateContainer { + func candidatePairAt(_ index: Int) -> (String, String) { + if state.isCandidateContainer, state.candidates.count > index { return state.candidates[index] } return ("", "") } - func candidateSelected(at index: Int) { + func candidatePairSelected(at index: Int) { if state.type == .ofSymbolTable, (0.. Int { guard let delegate = delegate else { return Int.max } let result = currentPageIndex * keyLabels.count + index - return result < delegate.candidateCountForController(self) ? result : Int.max + return result < delegate.candidatePairs().count ? result : Int.max } public var selectedCandidateIndex: Int {