SymbolNode // Add and call previous node references.

This commit is contained in:
ShikiSuen 2022-07-27 14:55:42 +08:00
parent b0cde41126
commit 0e8b027674
4 changed files with 10 additions and 3 deletions

View File

@ -440,8 +440,11 @@ enum InputState {
override public var type: StateType { .ofSymbolTable }
var node: SymbolNode
init(node: SymbolNode, isTypingVertical: Bool) {
init(node: SymbolNode, previous: SymbolNode? = nil, isTypingVertical: Bool) {
self.node = node
if let previous = previous {
self.node.previous = previous
}
let candidates = node.children?.map(\.title) ?? [String]()
super.init(
composingBuffer: "", cursorIndex: 0, candidates: candidates.map { ("", $0) },

View File

@ -59,7 +59,7 @@ extension KeyHandler {
|| ((input.isCursorBackward || input.isCursorForward) && input.isShiftHold)
if cancelCandidateKey {
if (state is InputState.AssociatedPhrases)
if state is InputState.AssociatedPhrases
|| mgrPrefs.useSCPCTypingMode
|| compositor.isEmpty
{
@ -72,6 +72,9 @@ extension KeyHandler {
} else {
stateCallback(buildInputtingState)
}
if let state = state as? InputState.SymbolTable, let nodePrevious = state.node.previous {
stateCallback(InputState.SymbolTable(node: nodePrevious, isTypingVertical: state.isTypingVertical))
}
return true
}

View File

@ -101,7 +101,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
if let children = node.children, !children.isEmpty {
handle(state: InputState.Empty()) //
handle(
state: InputState.SymbolTable(node: node, isTypingVertical: state.isTypingVertical)
state: InputState.SymbolTable(node: node, previous: state.node, isTypingVertical: state.isTypingVertical)
)
} else {
handle(state: InputState.Committing(textToCommit: node.title))

View File

@ -29,6 +29,7 @@ import Foundation
class SymbolNode {
var title: String
var children: [SymbolNode]?
var previous: SymbolNode?
init(_ title: String, _ children: [SymbolNode]? = nil) {
self.title = title