SessionCtl // Use an alternative way to keep IMKCandidates' visibility.

- We have no other way to solve the excessive-memory-usage problem without completely removing the instance container.
This commit is contained in:
ShikiSuen 2022-11-19 18:39:20 +08:00
parent 337cf84c8b
commit 1057a3fe82
2 changed files with 13 additions and 20 deletions

View File

@ -25,8 +25,6 @@ import UpdateSputnik
/// IMKInputController
@objc(SessionCtl) // ObjC IMK ObjC
public class SessionCtl: IMKInputController {
public static var allInstances: NSMutableOrderedSet = .init()
///
public static var areWeNerfing = false
@ -121,6 +119,15 @@ public class SessionCtl: IMKInputController {
/// 調
resetInputHandler(forceComposerCleanup: true)
}
// deactivateServer() activateServer()
//
// IMKCandidates
if PrefMgr.shared.useIMKCandidateWindow {
guard let imkC = ctlCandidateCurrent as? CtlCandidateIMK else { return }
if state.isCandidateContainer, !imkC.visible {
handle(state: state, replace: false)
}
}
}
}
@ -184,7 +191,7 @@ extension SessionCtl {
public override func activateServer(_ sender: Any!) {
_ = sender //
DispatchQueue.main.async { [self] in
if Self.allInstances.contains(self) { return }
if isActivated { return }
// activateServer nil
//
@ -207,7 +214,6 @@ extension SessionCtl {
state = IMEState.ofEmpty()
isActivated = true //
Self.allInstances.insert(self, at: 0)
setKeyLayout()
}
}
@ -220,7 +226,6 @@ extension SessionCtl {
isActivated = false
resetInputHandler() // Empty
switchState(IMEState.ofDeactivated())
Self.allInstances.remove(self)
}
}

View File

@ -42,24 +42,12 @@ extension SessionCtl {
if replace { state = newState }
switch newState.type {
case .ofDeactivated:
// commitComposition()
// clearInlineDisplay()
// IMK inputMode.didSet()
ctlCandidateCurrent.visible = false
popupCompositionBuffer.hide()
tooltipInstance.hide()
// commitComposition()
// clearInlineDisplay()
// deactivateServer() activateServer()
//
// IMKCandidates
//
if PrefMgr.shared.useIMKCandidateWindow {
for instance in Self.allInstances {
guard let instance = instance as? SessionCtl else { continue }
guard let imkC = instance.ctlCandidateCurrent as? CtlCandidateIMK else { continue }
if instance.state.isCandidateContainer, !imkC.visible {
instance.handle(state: instance.state, replace: false)
}
}
}
case .ofEmpty, .ofAbortion, .ofCommitting:
innerCircle: switch newState.type {
case .ofAbortion: