SessionCtl // Nil the candidateUI for inactive sessions.

- We don't nil the IMKCandidates on deinit() in order to avoid EXC_BAD_ACCESS error.
This commit is contained in:
ShikiSuen 2022-11-29 23:42:25 +08:00
parent 6f25182af0
commit 65462f4ad0
6 changed files with 22 additions and 28 deletions

View File

@ -49,7 +49,7 @@ public protocol InputHandlerDelegate {
var clientBundleIdentifier: String { get }
func callError(_ logMessage: String)
func switchState(_ newState: IMEStateProtocol)
func candidateController() -> CtlCandidateProtocol
func candidateController() -> CtlCandidateProtocol?
func candidateSelectionCalledByInputHandler(at index: Int)
func performUserPhraseOperation(addToFilter: Bool)
-> Bool

View File

@ -21,7 +21,7 @@ extension InputHandler {
/// - Returns: IMK
func handleCandidate(input: InputSignalProtocol) -> Bool {
guard let delegate = delegate else { return false }
var ctlCandidate = delegate.candidateController()
guard var ctlCandidate = delegate.candidateController() else { return false }
let state = delegate.state
guard !state.candidates.isEmpty else { return false }

View File

@ -29,16 +29,7 @@ public class SessionCtl: IMKInputController {
public static var areWeNerfing = false
///
public var candidateUI: CtlCandidateProtocol = {
let direction: NSUserInterfaceLayoutOrientation =
PrefMgr.shared.useHorizontalCandidateList ? .horizontal : .vertical
if #available(macOS 10.15, *) {
return PrefMgr.shared.useIMKCandidateWindow
? CtlCandidateIMK(direction) : CtlCandidateTDK(direction)
} else {
return CtlCandidateIMK(direction)
}
}()
public var candidateUI: CtlCandidateProtocol?
///
public var tooltipInstance = TooltipUI()
@ -210,7 +201,6 @@ extension SessionCtl {
// activateServer nil
//
inputHandler.delegate = self
candidateUI.delegate = self
// setValue() IMK activateServer() setValue()
inputHandler.clear() // handle State.Empty()
inputHandler.ensureKeyboardParser()
@ -241,6 +231,10 @@ extension SessionCtl {
isActivated = false
resetInputHandler() // Empty
switchState(IMEState.ofDeactivated())
// IMK nil IMK
if candidateUI is CtlCandidateTDK {
candidateUI = nil
}
}
}

View File

@ -16,7 +16,7 @@ extension SessionCtl: InputHandlerDelegate {
return client.bundleIdentifier() ?? ""
}
public func candidateController() -> CtlCandidateProtocol { candidateUI }
public func candidateController() -> CtlCandidateProtocol? { candidateUI }
public func candidateSelectionCalledByInputHandler(at index: Int) {
candidatePairSelected(at: index)

View File

@ -82,7 +82,7 @@ extension SessionCtl {
: .horizontal)
/// NSWindow()
candidateUI.visible = false
candidateUI?.visible = false
///
if #available(macOS 10.15, *) {
candidateUI =
@ -95,22 +95,22 @@ extension SessionCtl {
candidateUI = CtlCandidateIMK(candidateLayout)
}
candidateUI.candidateFont = Self.candidateFont(
candidateUI?.candidateFont = Self.candidateFont(
name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize
)
if PrefMgr.shared.cassetteEnabled {
candidateUI.tooltip =
candidateUI?.tooltip =
isVerticalTyping ? "📼" : "📼 " + NSLocalizedString("CIN Cassette Mode", comment: "")
}
if state.type == .ofAssociates {
candidateUI.tooltip =
candidateUI?.tooltip =
isVerticalTyping ? "" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "")
}
candidateUI.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
candidateUI.locale = {
candidateUI?.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
candidateUI?.locale = {
switch inputMode {
case .imeModeCHS: return "zh-Hans"
case .imeModeCHT:
@ -131,11 +131,11 @@ extension SessionCtl {
}
}
candidateUI.delegate = self //
candidateUI.visible = true
candidateUI?.delegate = self //
candidateUI?.visible = true
if isVerticalTyping {
candidateUI.set(
candidateUI?.set(
windowTopLeftPoint: NSPoint(
x: lineHeightRect().origin.x + lineHeightRect().size.width + 4.0, y: lineHeightRect().origin.y - 4.0
),
@ -143,7 +143,7 @@ extension SessionCtl {
useGCD: true
)
} else {
candidateUI.set(
candidateUI?.set(
windowTopLeftPoint: NSPoint(x: lineHeightRect().origin.x, y: lineHeightRect().origin.y - 4.0),
bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0,
useGCD: true

View File

@ -45,7 +45,7 @@ extension SessionCtl {
// commitComposition()
// clearInlineDisplay()
// IMK inputMode.didSet()
candidateUI.visible = false
candidateUI?.visible = false
popupCompositionBuffer.hide()
tooltipInstance.hide()
case .ofEmpty, .ofAbortion, .ofCommitting:
@ -58,7 +58,7 @@ extension SessionCtl {
if replace { state = IMEState.ofEmpty() }
default: break innerCircle
}
candidateUI.visible = false
candidateUI?.visible = false
// .Abortion
if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) {
commit(text: previous.displayedText)
@ -67,12 +67,12 @@ extension SessionCtl {
clearInlineDisplay()
inputHandler.clear()
case .ofInputting:
candidateUI.visible = false
candidateUI?.visible = false
commit(text: newState.textToCommit)
setInlineDisplayWithCursor()
showTooltip(newState.tooltip, duration: 1) //
case .ofMarking:
candidateUI.visible = false
candidateUI?.visible = false
setInlineDisplayWithCursor()
showTooltip(newState.tooltip)
case .ofCandidates, .ofAssociates, .ofSymbolTable: