SessionCtl // Track and handle deactivated states correctly.

This commit is contained in:
ShikiSuen 2022-10-10 18:06:10 +08:00
parent 81feeb341c
commit 0d79e83777
2 changed files with 16 additions and 1 deletions

View File

@ -24,6 +24,8 @@ import TooltipUI
/// IMKInputController /// IMKInputController
@objc(SessionCtl) // ObjC IMK ObjC @objc(SessionCtl) // ObjC IMK ObjC
public class SessionCtl: IMKInputController { public class SessionCtl: IMKInputController {
public static var allInstances: Set<SessionCtl> = .init()
/// ///
public static var areWeNerfing = false public static var areWeNerfing = false
@ -197,6 +199,7 @@ extension SessionCtl {
} }
handle(state: IMEState.ofEmpty()) handle(state: IMEState.ofEmpty())
Self.allInstances.insert(self)
} }
/// ///
@ -205,6 +208,7 @@ extension SessionCtl {
_ = sender // _ = sender //
resetKeyHandler() // Empty resetKeyHandler() // Empty
handle(state: IMEState.ofDeactivated()) handle(state: IMEState.ofDeactivated())
Self.allInstances.remove(self)
} }
/// ///

View File

@ -35,6 +35,18 @@ extension SessionCtl {
clearInlineDisplay() clearInlineDisplay()
// //
keyHandler.clear() keyHandler.clear()
// deactivateServer() activateServer()
//
// IMKCandidates
//
if PrefMgr.shared.useIMKCandidateWindow {
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)
}
}
}
case .ofEmpty, .ofAbortion: case .ofEmpty, .ofAbortion:
var previous = previous var previous = previous
if state.type == .ofAbortion { if state.type == .ofAbortion {
@ -48,7 +60,6 @@ extension SessionCtl {
commit(text: previous.displayedText) commit(text: previous.displayedText)
} }
// //
ctlCandidateCurrent.visible = false
tooltipInstance.hide() tooltipInstance.hide()
clearInlineDisplay() clearInlineDisplay()
// //