diff --git a/Source/Modules/InputHandler_Core.swift b/Source/Modules/InputHandler_Core.swift index 826f81b9..f0b657f1 100644 --- a/Source/Modules/InputHandler_Core.swift +++ b/Source/Modules/InputHandler_Core.swift @@ -37,6 +37,7 @@ public protocol InputHandlerProtocol { candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool, skipObservation: Bool ) func updateUnigramData() -> Bool + func previewCompositionBufferForCandidate(at index: Int) } extension InputHandlerProtocol { @@ -67,6 +68,7 @@ public protocol InputHandlerDelegate { func switchState(_ newState: IMEStateProtocol) func candidateController() -> CtlCandidateProtocol? func candidateSelectionConfirmedByInputHandler(at index: Int) + func setInlineDisplayWithCursor() func performUserPhraseOperation(addToFilter: Bool) -> Bool } @@ -408,6 +410,28 @@ public class InputHandler: InputHandlerProtocol { return arrResult } + public func previewCompositionBufferForCandidate(at index: Int) { + guard var delegate = delegate, delegate.state.type == .ofCandidates, + (0 ..< delegate.state.candidates.count).contains(index) + else { + return + } + let gridBackup = compositor.hardCopy + defer { compositor = gridBackup } + var theState = delegate.state + let highlightedPair = theState.candidates[index] + consolidateNode( + candidate: highlightedPair, respectCursorPushing: false, + preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection, + skipObservation: true + ) + let inputting = generateStateOfInputting(sansReading: true) + theState.data.displayTextSegments = inputting.data.displayTextSegments + theState.data.cursor = inputting.cursor + delegate.state = theState // 直接就地取代,不經過 switchState 處理,免得選字窗被重新載入。 + delegate.setInlineDisplayWithCursor() + } + // MARK: - Extracted methods and functions (Tekkon). var isComposerOrCalligrapherEmpty: Bool {