SessionCtl // Nil the inputHandler for inactive sessions.

This commit is contained in:
ShikiSuen 2022-11-30 00:21:48 +08:00
parent 65462f4ad0
commit b8d6a828ba
5 changed files with 19 additions and 15 deletions

View File

@ -18,7 +18,7 @@ import Shared
extension InputHandler { extension InputHandler {
/// ///
/// - Remark: inputHandler.handleEvent() IMKCandidates /// - Remark: inputHandler?.handleEvent() IMKCandidates
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - Returns: IMK /// - Returns: IMK

View File

@ -66,9 +66,7 @@ public class SessionCtl: IMKInputController {
private static var isASCIIModeForAllClients = false // private static var isASCIIModeForAllClients = false //
/// 調 /// 調
var inputHandler: InputHandlerProtocol = InputHandler( var inputHandler: InputHandlerProtocol?
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
)
/// ///
public var state: IMEStateProtocol = IMEState.ofEmpty() { public var state: IMEStateProtocol = IMEState.ofEmpty() {
didSet { didSet {
@ -113,10 +111,10 @@ public class SessionCtl: IMKInputController {
if oldValue != inputMode, inputMode != .imeModeNULL { if oldValue != inputMode, inputMode != .imeModeNULL {
// ---------------------------- // ----------------------------
/// ///
inputHandler.currentLM = LMMgr.currentLM // inputHandler?.currentLM = LMMgr.currentLM //
inputHandler.currentUOM = LMMgr.currentUOM inputHandler?.currentUOM = LMMgr.currentUOM
/// ///
inputHandler.ensureKeyboardParser() inputHandler?.ensureKeyboardParser()
/// ///
syncBaseLMPrefs() syncBaseLMPrefs()
/// 調 /// 調
@ -145,7 +143,10 @@ public class SessionCtl: IMKInputController {
override public init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) { override public init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
super.init(server: server, delegate: delegate, client: inputClient) super.init(server: server, delegate: delegate, client: inputClient)
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
inputHandler.delegate = self inputHandler = InputHandler(
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
)
inputHandler?.delegate = self
syncBaseLMPrefs() syncBaseLMPrefs()
// //
activateServer(inputClient) activateServer(inputClient)
@ -175,6 +176,7 @@ extension SessionCtl {
/// 調 /// 調
public func resetInputHandler(forceComposerCleanup forceCleanup: Bool = false) { public func resetInputHandler(forceComposerCleanup forceCleanup: Bool = false) {
guard let inputHandler = inputHandler else { return }
var textToCommit = "" var textToCommit = ""
// //
let sansReading: Bool = let sansReading: Bool =
@ -198,12 +200,12 @@ extension SessionCtl {
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
if isActivated { return } if isActivated { return }
// activateServer nil
//
inputHandler.delegate = self
// setValue() IMK activateServer() setValue() // setValue() IMK activateServer() setValue()
inputHandler.clear() // handle State.Empty() inputHandler = InputHandler(
inputHandler.ensureKeyboardParser() lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
)
inputHandler?.delegate = self
syncBaseLMPrefs()
Self.theShiftKeyDetector.alsoToggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift Self.theShiftKeyDetector.alsoToggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
Self.isVerticalTyping = isVerticalTyping Self.isVerticalTyping = isVerticalTyping
@ -231,6 +233,7 @@ extension SessionCtl {
isActivated = false isActivated = false
resetInputHandler() // Empty resetInputHandler() // Empty
switchState(IMEState.ofDeactivated()) switchState(IMEState.ofDeactivated())
inputHandler = nil
// IMK nil IMK // IMK nil IMK
if candidateUI is CtlCandidateTDK { if candidateUI is CtlCandidateTDK {
candidateUI = nil candidateUI = nil

View File

@ -98,6 +98,7 @@ extension SessionCtl: CtlCandidateDelegate {
} }
public func candidatePairSelected(at index: Int) { public func candidatePairSelected(at index: Int) {
guard let inputHandler = inputHandler else { return }
if state.type == .ofSymbolTable, (0..<state.node.members.count).contains(index) { if state.type == .ofSymbolTable, (0..<state.node.members.count).contains(index) {
let node = state.node.members[index] let node = state.node.members[index]
if !node.members.isEmpty { if !node.members.isEmpty {

View File

@ -101,7 +101,7 @@ extension SessionCtl {
if event.type == .flagsChanged { return false } if event.type == .flagsChanged { return false }
/// ///
guard client() != nil else { return false } guard let inputHandler = inputHandler, client() != nil else { return false }
var eventToDeal = event var eventToDeal = event

View File

@ -65,7 +65,7 @@ extension SessionCtl {
} }
showTooltip(newState.tooltip, duration: 1) // showTooltip(newState.tooltip, duration: 1) //
clearInlineDisplay() clearInlineDisplay()
inputHandler.clear() inputHandler?.clear()
case .ofInputting: case .ofInputting:
candidateUI?.visible = false candidateUI?.visible = false
commit(text: newState.textToCommit) commit(text: newState.textToCommit)