SessionCtl // Disable setMarkedText() on deactivateServer().
This commit is contained in:
parent
b203e46398
commit
4d213f569b
|
@ -48,6 +48,9 @@ public class SessionCtl: IMKInputController {
|
|||
/// 浮動組字窗的副本。
|
||||
public var popupCompositionBuffer = PopupCompositionBuffer()
|
||||
|
||||
/// 用來標記當前副本是否已處於活動狀態。
|
||||
public var isActivated = false
|
||||
|
||||
// MARK: -
|
||||
|
||||
/// 當前 Caps Lock 按鍵是否被摁下。
|
||||
|
@ -207,6 +210,7 @@ extension SessionCtl {
|
|||
}
|
||||
|
||||
switchState(IMEState.ofEmpty())
|
||||
isActivated = true // 登記啟用狀態。
|
||||
Self.allInstances.insert(self)
|
||||
}
|
||||
|
||||
|
@ -214,6 +218,7 @@ extension SessionCtl {
|
|||
/// - Parameter sender: 呼叫了該函式的客體(無須使用)。
|
||||
public override func deactivateServer(_ sender: Any!) {
|
||||
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
||||
isActivated = false
|
||||
resetInputHandler() // 這條會自動搞定 Empty 狀態。
|
||||
switchState(IMEState.ofDeactivated())
|
||||
Self.allInstances.remove(self)
|
||||
|
|
|
@ -48,7 +48,7 @@ extension SessionCtl {
|
|||
if previous.hasComposition {
|
||||
commit(text: previous.displayedText)
|
||||
}
|
||||
clearInlineDisplay() // 該函式有對 client 做 guard-let 保護,不會出現上游 #346 的問題。
|
||||
// clearInlineDisplay() // 不需要,否則會觸發無限迴圈。
|
||||
// 最後一道保險
|
||||
inputHandler.clear()
|
||||
// 特殊處理:deactivateServer() 可能會遲於另一個客體會話的 activateServer() 執行。
|
||||
|
@ -150,7 +150,7 @@ extension SessionCtl {
|
|||
|
||||
/// 把 setMarkedText 包裝一下,按需啟用 GCD。
|
||||
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 {
|
||||
DispatchQueue.main.async {
|
||||
client.setMarkedText(string, selectionRange: selectionRange, replacementRange: replacementRange)
|
||||
|
|
Loading…
Reference in New Issue