SessionCtl // ctlCandidateCurrent -> candidateUI.

This commit is contained in:
ShikiSuen 2022-11-25 11:58:03 +08:00
parent 06e984b6f9
commit 0b2a046885
5 changed files with 25 additions and 25 deletions

View File

@ -29,7 +29,7 @@ public class SessionCtl: IMKInputController {
public static var areWeNerfing = false
///
public var ctlCandidateCurrent: CtlCandidateProtocol = {
public var candidateUI: CtlCandidateProtocol = {
let direction: NSUserInterfaceLayoutOrientation =
PrefMgr.shared.useHorizontalCandidateList ? .horizontal : .vertical
if #available(macOS 10.15, *) {
@ -135,7 +135,7 @@ public class SessionCtl: IMKInputController {
//
// IMKCandidates
if PrefMgr.shared.useIMKCandidateWindow {
guard let imkC = ctlCandidateCurrent as? CtlCandidateIMK else { return }
guard let imkC = candidateUI as? CtlCandidateIMK else { return }
if state.isCandidateContainer, !imkC.visible {
handle(state: state, replace: false)
}
@ -209,7 +209,8 @@ extension SessionCtl {
// activateServer nil
//
if inputHandler.delegate == nil { inputHandler.delegate = self }
inputHandler.delegate = self
candidateUI.delegate = self
// setValue() IMK activateServer() setValue()
inputHandler.clear() // handle State.Empty()
inputHandler.ensureKeyboardParser()

View File

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

View File

@ -82,35 +82,35 @@ extension SessionCtl {
: .horizontal)
/// NSWindow()
ctlCandidateCurrent.visible = false
candidateUI.visible = false
///
if #available(macOS 10.15, *) {
ctlCandidateCurrent =
candidateUI =
PrefMgr.shared.useIMKCandidateWindow
? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
if let candidateTDK = ctlCandidateCurrent as? CtlCandidateTDK {
if let candidateTDK = candidateUI as? CtlCandidateTDK {
candidateTDK.maxLinesPerPage = isVerticalTyping ? 1 : 3
}
} else {
ctlCandidateCurrent = CtlCandidateIMK(candidateLayout)
candidateUI = CtlCandidateIMK(candidateLayout)
}
ctlCandidateCurrent.candidateFont = Self.candidateFont(
candidateUI.candidateFont = Self.candidateFont(
name: PrefMgr.shared.candidateTextFontName, size: PrefMgr.shared.candidateListTextSize
)
if PrefMgr.shared.cassetteEnabled {
ctlCandidateCurrent.tooltip =
candidateUI.tooltip =
isVerticalTyping ? "📼" : "📼 " + NSLocalizedString("CIN Cassette Mode", comment: "")
}
if state.type == .ofAssociates {
ctlCandidateCurrent.tooltip =
candidateUI.tooltip =
isVerticalTyping ? "" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "")
}
ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
ctlCandidateCurrent.locale = {
candidateUI.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
candidateUI.locale = {
switch inputMode {
case .imeModeCHS: return "zh-Hans"
case .imeModeCHT:
@ -124,18 +124,18 @@ extension SessionCtl {
if #available(macOS 10.14, *) {
// Spotlight IMK
if let ctlCandidateCurrent = ctlCandidateCurrent as? CtlCandidateIMK {
if let ctlCandidateCurrent = candidateUI as? CtlCandidateIMK {
while ctlCandidateCurrent.windowLevel() <= client.windowLevel() {
ctlCandidateCurrent.setWindowLevel(UInt64(max(0, client.windowLevel() + 1000)))
}
}
}
ctlCandidateCurrent.delegate = self //
ctlCandidateCurrent.visible = true
candidateUI.delegate = self //
candidateUI.visible = true
if isVerticalTyping {
ctlCandidateCurrent.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 {
ctlCandidateCurrent.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()
ctlCandidateCurrent.visible = false
candidateUI.visible = false
popupCompositionBuffer.hide()
tooltipInstance.hide()
case .ofEmpty, .ofAbortion, .ofCommitting:
@ -58,22 +58,21 @@ extension SessionCtl {
if replace { state = IMEState.ofEmpty() }
default: break innerCircle
}
ctlCandidateCurrent.visible = false
candidateUI.visible = false
// .Abortion
if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) {
commit(text: previous.displayedText)
}
showTooltip(newState.tooltip, duration: 1) //
clearInlineDisplay()
//
inputHandler.clear()
case .ofInputting:
ctlCandidateCurrent.visible = false
candidateUI.visible = false
commit(text: newState.textToCommit)
setInlineDisplayWithCursor()
showTooltip(newState.tooltip, duration: 1) //
case .ofMarking:
ctlCandidateCurrent.visible = false
candidateUI.visible = false
setInlineDisplayWithCursor()
showTooltip(newState.tooltip)
case .ofCandidates, .ofAssociates, .ofSymbolTable:

View File

@ -62,8 +62,8 @@ extension SessionCtl {
let annotation = reverseLookup(for: currentCandidate).joined(separator: "\n")
guard !annotation.isEmpty else { return }
vCLog("Current Annotation: \(annotation)")
DispatchQueue.main.async {
guard let imkCandidates = self.ctlCandidateCurrent as? CtlCandidateIMK else { return }
DispatchQueue.main.async { [self] in
guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return }
imkCandidates.showAnnotation(.init(string: annotation))
}
}