SessionCtl // Add (Bool)replaceCurrent to handle(event).

This commit is contained in:
ShikiSuen 2022-10-10 19:59:53 +08:00
parent 0d79e83777
commit 0956e043fd
1 changed files with 17 additions and 18 deletions

View File

@ -21,10 +21,10 @@ extension SessionCtl {
/// 使 SessionCtl
///
/// - Parameter newState:
public func handle(state newState: IMEStateProtocol) {
let previous = state
state = newState
switch state.type {
public func handle(state newState: IMEStateProtocol, replaceCurrent: Bool = true) {
var previous = state
if replaceCurrent { state = newState }
switch newState.type {
case .ofDeactivated:
ctlCandidateCurrent.visible = false
popupCompositionBuffer.hide()
@ -43,20 +43,19 @@ extension SessionCtl {
for instance in Self.allInstances {
guard let imkC = instance.ctlCandidateCurrent as? CtlCandidateIMK else { continue }
if instance.state.isCandidateContainer, !imkC.visible {
instance.handle(state: instance.state)
instance.handle(state: instance.state, replaceCurrent: false)
}
}
}
case .ofEmpty, .ofAbortion:
var previous = previous
if state.type == .ofAbortion {
state = IMEState.ofEmpty()
previous = state
if newState.type == .ofAbortion {
previous = IMEState.ofEmpty()
if replaceCurrent { state = previous }
}
ctlCandidateCurrent.visible = false
tooltipInstance.hide()
// .Abortion
if previous.hasComposition, state.type != .ofAbortion {
if previous.hasComposition, newState.type != .ofAbortion {
commit(text: previous.displayedText)
}
//
@ -67,7 +66,7 @@ extension SessionCtl {
case .ofCommitting:
ctlCandidateCurrent.visible = false
tooltipInstance.hide()
let textToCommit = state.textToCommit
let textToCommit = newState.textToCommit
if !textToCommit.isEmpty { commit(text: textToCommit) }
clearInlineDisplay()
//
@ -75,19 +74,19 @@ extension SessionCtl {
case .ofInputting:
ctlCandidateCurrent.visible = false
tooltipInstance.hide()
let textToCommit = state.textToCommit
let textToCommit = newState.textToCommit
if !textToCommit.isEmpty { commit(text: textToCommit) }
setInlineDisplayWithCursor()
if !state.tooltip.isEmpty {
show(tooltip: state.tooltip)
if !newState.tooltip.isEmpty {
show(tooltip: newState.tooltip)
}
case .ofMarking:
ctlCandidateCurrent.visible = false
setInlineDisplayWithCursor()
if state.tooltip.isEmpty {
if newState.tooltip.isEmpty {
tooltipInstance.hide()
} else {
show(tooltip: state.tooltip)
show(tooltip: newState.tooltip)
}
case .ofCandidates, .ofAssociates, .ofSymbolTable:
tooltipInstance.hide()
@ -96,10 +95,10 @@ extension SessionCtl {
default: break
}
//
if state.hasComposition, PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) {
if newState.hasComposition, PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) {
popupCompositionBuffer.isTypingDirectionVertical = isVerticalTyping
popupCompositionBuffer.show(
state: state, at: lineHeightRect(zeroCursor: true).origin
state: newState, at: lineHeightRect(zeroCursor: true).origin
)
} else {
popupCompositionBuffer.hide()