SessionCtl // Disable setMarkedText() on deactivateServer().

This commit is contained in:
ShikiSuen 2022-11-04 16:30:39 +08:00
parent b203e46398
commit 4d213f569b
2 changed files with 7 additions and 2 deletions

View File

@ -48,6 +48,9 @@ public class SessionCtl: IMKInputController {
/// ///
public var popupCompositionBuffer = PopupCompositionBuffer() public var popupCompositionBuffer = PopupCompositionBuffer()
///
public var isActivated = false
// MARK: - // MARK: -
/// Caps Lock /// Caps Lock
@ -207,6 +210,7 @@ extension SessionCtl {
} }
switchState(IMEState.ofEmpty()) switchState(IMEState.ofEmpty())
isActivated = true //
Self.allInstances.insert(self) Self.allInstances.insert(self)
} }
@ -214,6 +218,7 @@ extension SessionCtl {
/// - Parameter sender: 使 /// - Parameter sender: 使
public override func deactivateServer(_ sender: Any!) { public override func deactivateServer(_ sender: Any!) {
_ = sender // _ = sender //
isActivated = false
resetInputHandler() // Empty resetInputHandler() // Empty
switchState(IMEState.ofDeactivated()) switchState(IMEState.ofDeactivated())
Self.allInstances.remove(self) Self.allInstances.remove(self)

View File

@ -48,7 +48,7 @@ extension SessionCtl {
if previous.hasComposition { if previous.hasComposition {
commit(text: previous.displayedText) commit(text: previous.displayedText)
} }
clearInlineDisplay() // client guard-let #346 // clearInlineDisplay() //
// //
inputHandler.clear() inputHandler.clear()
// deactivateServer() activateServer() // deactivateServer() activateServer()
@ -150,7 +150,7 @@ extension SessionCtl {
/// setMarkedText GCD /// setMarkedText GCD
public func doSetMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) { public func doSetMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) {
guard let client = client() else { return } guard isActivated, let client = client() else { return }
if let myID = Bundle.main.bundleIdentifier, let clientID = client.bundleIdentifier(), myID == clientID { if let myID = Bundle.main.bundleIdentifier, let clientID = client.bundleIdentifier(), myID == clientID {
DispatchQueue.main.async { DispatchQueue.main.async {
client.setMarkedText(string, selectionRange: selectionRange, replacementRange: replacementRange) client.setMarkedText(string, selectionRange: selectionRange, replacementRange: replacementRange)