InputHandler // Implement previewCompositionBufferForCandidate().

This commit is contained in:
ShikiSuen 2023-03-09 23:02:40 +08:00
parent 8535fc1711
commit 79aa073b7a
1 changed files with 24 additions and 0 deletions

View File

@ -37,6 +37,7 @@ public protocol InputHandlerProtocol {
candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool, skipObservation: Bool candidate: (keyArray: [String], value: String), respectCursorPushing: Bool, preConsolidate: Bool, skipObservation: Bool
) )
func updateUnigramData() -> Bool func updateUnigramData() -> Bool
func previewCompositionBufferForCandidate(at index: Int)
} }
extension InputHandlerProtocol { extension InputHandlerProtocol {
@ -67,6 +68,7 @@ public protocol InputHandlerDelegate {
func switchState(_ newState: IMEStateProtocol) func switchState(_ newState: IMEStateProtocol)
func candidateController() -> CtlCandidateProtocol? func candidateController() -> CtlCandidateProtocol?
func candidateSelectionConfirmedByInputHandler(at index: Int) func candidateSelectionConfirmedByInputHandler(at index: Int)
func setInlineDisplayWithCursor()
func performUserPhraseOperation(addToFilter: Bool) func performUserPhraseOperation(addToFilter: Bool)
-> Bool -> Bool
} }
@ -408,6 +410,28 @@ public class InputHandler: InputHandlerProtocol {
return arrResult 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). // MARK: - Extracted methods and functions (Tekkon).
var isComposerOrCalligrapherEmpty: Bool { var isComposerOrCalligrapherEmpty: Bool {