Repo // Simplify certain naming methods.

This commit is contained in:
ShikiSuen 2022-09-24 20:18:24 +08:00
parent e9137b9e53
commit 5815a49359
5 changed files with 43 additions and 43 deletions

View File

@ -96,7 +96,7 @@ extension IMEState {
} }
public static func ofInputting(displayTextSegments: [String], cursor: Int) -> IMEState { public static func ofInputting(displayTextSegments: [String], cursor: Int) -> IMEState {
var result = IMEState.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor) var result = Self.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofInputting result.type = .ofInputting
return result return result
} }
@ -106,7 +106,7 @@ extension IMEState {
) )
-> IMEState -> IMEState
{ {
var result = IMEState.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor) var result = Self.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofMarking result.type = .ofMarking
result.data.marker = marker result.data.marker = marker
result.data.markedReadings = markedReadings result.data.markedReadings = markedReadings
@ -117,7 +117,7 @@ extension IMEState {
public static func ofCandidates(candidates: [(String, String)], displayTextSegments: [String], cursor: Int) public static func ofCandidates(candidates: [(String, String)], displayTextSegments: [String], cursor: Int)
-> IMEState -> IMEState
{ {
var result = IMEState.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor) var result = Self.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofCandidates result.type = .ofCandidates
result.data.candidates = candidates result.data.candidates = candidates
return result return result
@ -154,7 +154,7 @@ extension IMEState {
public var convertedToInputting: IMEStateProtocol { public var convertedToInputting: IMEStateProtocol {
if type == .ofInputting { return self } if type == .ofInputting { return self }
var result = IMEState.ofInputting(displayTextSegments: data.displayTextSegments, cursor: data.cursor) var result = Self.ofInputting(displayTextSegments: data.displayTextSegments, cursor: data.cursor)
result.tooltip = data.tooltipBackupForInputting result.tooltip = data.tooltipBackupForInputting
result.isVerticalTyping = isVerticalTyping result.isVerticalTyping = isVerticalTyping
return result return result

View File

@ -18,7 +18,7 @@ extension ctlInputMethod: KeyHandlerDelegate {
return client.bundleIdentifier() ?? "" return client.bundleIdentifier() ?? ""
} }
func ctlCandidate() -> CtlCandidateProtocol { ctlInputMethod.ctlCandidateCurrent } func ctlCandidate() -> CtlCandidateProtocol { Self.ctlCandidateCurrent }
func candidateSelectionCalledByKeyHandler(at index: Int) { func candidateSelectionCalledByKeyHandler(at index: Int) {
candidateSelected(at: index) candidateSelected(at: index)

View File

@ -58,14 +58,14 @@ extension ctlInputMethod {
}() }()
// NSAttributedTextView // NSAttributedTextView
do { do {
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
ctlInputMethod.tooltipInstance = .init() Self.tooltipInstance = .init()
if state.type == .ofMarking { if state.type == .ofMarking {
ctlInputMethod.tooltipInstance.setColor(state: state.data.tooltipColorState) Self.tooltipInstance.setColor(state: state.data.tooltipColorState)
} }
} }
// //
ctlInputMethod.tooltipInstance.show( Self.tooltipInstance.show(
tooltip: tooltip, at: finalOrigin, tooltip: tooltip, at: finalOrigin,
bottomOutOfScreenAdjustmentHeight: delta, direction: tooltipContentDirection bottomOutOfScreenAdjustmentHeight: delta, direction: tooltipContentDirection
) )
@ -80,7 +80,7 @@ extension ctlInputMethod {
} }
if isVerticalTyping { return true } if isVerticalTyping { return true }
// IMK // IMK
guard ctlInputMethod.ctlCandidateCurrent is CtlCandidateUniversal else { return false } guard Self.ctlCandidateCurrent is CtlCandidateUniversal else { return false }
// 使 // 使
// //
// 使 // 使
@ -93,7 +93,7 @@ extension ctlInputMethod {
state.isVerticalCandidateWindow = (isCandidateWindowVertical || !PrefMgr.shared.useHorizontalCandidateList) state.isVerticalCandidateWindow = (isCandidateWindowVertical || !PrefMgr.shared.useHorizontalCandidateList)
ctlInputMethod.ctlCandidateCurrent.delegate = nil Self.ctlCandidateCurrent.delegate = nil
/// currentLayout /// currentLayout
/// ctlCandidate() SymbolTable /// ctlCandidate() SymbolTable
@ -106,7 +106,7 @@ extension ctlInputMethod {
? CandidateLayout.vertical ? CandidateLayout.vertical
: CandidateLayout.horizontal) : CandidateLayout.horizontal)
ctlInputMethod.ctlCandidateCurrent = Self.ctlCandidateCurrent =
PrefMgr.shared.useIMKCandidateWindow PrefMgr.shared.useIMKCandidateWindow
? CtlCandidateIMK(candidateLayout) : CtlCandidateUniversal(candidateLayout) ? CtlCandidateIMK(candidateLayout) : CtlCandidateUniversal(candidateLayout)
@ -122,10 +122,10 @@ extension ctlInputMethod {
return NSFont.systemFont(ofSize: size) return NSFont.systemFont(ofSize: size)
} }
ctlInputMethod.ctlCandidateCurrent.keyLabelFont = labelFont( Self.ctlCandidateCurrent.keyLabelFont = labelFont(
name: PrefMgr.shared.candidateKeyLabelFontName, size: keyLabelSize name: PrefMgr.shared.candidateKeyLabelFontName, size: keyLabelSize
) )
ctlInputMethod.ctlCandidateCurrent.candidateFont = ctlInputMethod.candidateFont( Self.ctlCandidateCurrent.candidateFont = Self.candidateFont(
name: PrefMgr.shared.candidateTextFontName, size: textSize name: PrefMgr.shared.candidateTextFontName, size: textSize
) )
@ -133,14 +133,14 @@ extension ctlInputMethod {
let keyLabels = let keyLabels =
candidateKeys.count > 4 ? Array(candidateKeys) : Array(CandidateKey.defaultKeys) candidateKeys.count > 4 ? Array(candidateKeys) : Array(CandidateKey.defaultKeys)
let keyLabelSuffix = state.type == .ofAssociates ? "^" : "" let keyLabelSuffix = state.type == .ofAssociates ? "^" : ""
ctlInputMethod.ctlCandidateCurrent.keyLabels = keyLabels.map { Self.ctlCandidateCurrent.keyLabels = keyLabels.map {
CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix) CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix)
} }
ctlInputMethod.ctlCandidateCurrent.delegate = self Self.ctlCandidateCurrent.delegate = self
ctlInputMethod.ctlCandidateCurrent.showPageButtons = PrefMgr.shared.showPageButtonsInCandidateWindow Self.ctlCandidateCurrent.showPageButtons = PrefMgr.shared.showPageButtonsInCandidateWindow
ctlInputMethod.ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier Self.ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
ctlInputMethod.ctlCandidateCurrent.locale = { Self.ctlCandidateCurrent.locale = {
switch inputMode { switch inputMode {
case .imeModeCHS: return "zh-Hans" case .imeModeCHS: return "zh-Hans"
case .imeModeCHT: case .imeModeCHT:
@ -151,28 +151,28 @@ extension ctlInputMethod {
default: return "" default: return ""
} }
}() }()
ctlInputMethod.ctlCandidateCurrent.reloadData() Self.ctlCandidateCurrent.reloadData()
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {
// Spotlight IMK // Spotlight IMK
if let ctlCandidateCurrent = ctlInputMethod.ctlCandidateCurrent as? CtlCandidateIMK { if let ctlCandidateCurrent = Self.ctlCandidateCurrent as? CtlCandidateIMK {
while ctlCandidateCurrent.windowLevel() <= client.windowLevel() { while ctlCandidateCurrent.windowLevel() <= client.windowLevel() {
ctlCandidateCurrent.setWindowLevel(UInt64(max(0, client.windowLevel() + 1000))) ctlCandidateCurrent.setWindowLevel(UInt64(max(0, client.windowLevel() + 1000)))
} }
} }
} }
ctlInputMethod.ctlCandidateCurrent.visible = true Self.ctlCandidateCurrent.visible = true
if isVerticalTyping { if isVerticalTyping {
ctlInputMethod.ctlCandidateCurrent.set( Self.ctlCandidateCurrent.set(
windowTopLeftPoint: NSPoint( windowTopLeftPoint: NSPoint(
x: lineHeightRect().origin.x + lineHeightRect().size.width + 4.0, y: lineHeightRect().origin.y - 4.0 x: lineHeightRect().origin.x + lineHeightRect().size.width + 4.0, y: lineHeightRect().origin.y - 4.0
), ),
bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0 bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0
) )
} else { } else {
ctlInputMethod.ctlCandidateCurrent.set( Self.ctlCandidateCurrent.set(
windowTopLeftPoint: NSPoint(x: lineHeightRect().origin.x, y: lineHeightRect().origin.y - 4.0), windowTopLeftPoint: NSPoint(x: lineHeightRect().origin.x, y: lineHeightRect().origin.y - 4.0),
bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0 bottomOutOfScreenAdjustmentHeight: lineHeightRect().size.height + 4.0
) )

View File

@ -143,7 +143,7 @@ extension ctlInputMethod {
// interpretKeyEvents() // interpretKeyEvents()
// - imkCandidates.interpretKeyEvents() // - imkCandidates.interpretKeyEvents()
// - delegate ctlInputMethod KeyHandler // - delegate ctlInputMethod KeyHandler
if let imkCandidates = ctlInputMethod.ctlCandidateCurrent as? CtlCandidateIMK, imkCandidates.visible { if let imkCandidates = Self.ctlCandidateCurrent as? CtlCandidateIMK, imkCandidates.visible {
let event: NSEvent = CtlCandidateIMK.replaceNumPadKeyCodes(target: eventToDeal) ?? eventToDeal let event: NSEvent = CtlCandidateIMK.replaceNumPadKeyCodes(target: eventToDeal) ?? eventToDeal
// Shift+Enter delegate keyHandler // Shift+Enter delegate keyHandler
@ -206,7 +206,7 @@ extension ctlInputMethod {
let newEvent = event.reinitiate(characters: newChar) let newEvent = event.reinitiate(characters: newChar)
if let newEvent = newEvent { if let newEvent = newEvent {
if PrefMgr.shared.useSCPCTypingMode, state.type == .ofAssociates { if PrefMgr.shared.useSCPCTypingMode, state.type == .ofAssociates {
// input.isShiftHold ctlInputMethod.handle() // input.isShiftHold Self.handle()
return event.isShiftHold ? true : commonEventHandler(event) return event.isShiftHold ? true : commonEventHandler(event)
} else { } else {
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {

View File

@ -24,9 +24,9 @@ extension ctlInputMethod {
state = newState state = newState
switch state.type { switch state.type {
case .ofDeactivated: case .ofDeactivated:
ctlInputMethod.ctlCandidateCurrent.delegate = nil Self.ctlCandidateCurrent.delegate = nil
ctlInputMethod.ctlCandidateCurrent.visible = false Self.ctlCandidateCurrent.visible = false
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
if previous.hasComposition { if previous.hasComposition {
commit(text: previous.displayedText) commit(text: previous.displayedText)
} }
@ -39,29 +39,29 @@ extension ctlInputMethod {
state = IMEState.ofEmpty() state = IMEState.ofEmpty()
previous = state previous = state
} }
ctlInputMethod.ctlCandidateCurrent.visible = false Self.ctlCandidateCurrent.visible = false
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
// .Abortion // .Abortion
if previous.hasComposition, state.type != .ofAbortion { if previous.hasComposition, state.type != .ofAbortion {
commit(text: previous.displayedText) commit(text: previous.displayedText)
} }
// //
ctlInputMethod.ctlCandidateCurrent.visible = false Self.ctlCandidateCurrent.visible = false
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
clearInlineDisplay() clearInlineDisplay()
// //
keyHandler.clear() keyHandler.clear()
case .ofCommitting: case .ofCommitting:
ctlInputMethod.ctlCandidateCurrent.visible = false Self.ctlCandidateCurrent.visible = false
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
let textToCommit = state.textToCommit let textToCommit = state.textToCommit
if !textToCommit.isEmpty { commit(text: textToCommit) } if !textToCommit.isEmpty { commit(text: textToCommit) }
clearInlineDisplay() clearInlineDisplay()
// //
keyHandler.clear() keyHandler.clear()
case .ofInputting: case .ofInputting:
ctlInputMethod.ctlCandidateCurrent.visible = false Self.ctlCandidateCurrent.visible = false
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
let textToCommit = state.textToCommit let textToCommit = state.textToCommit
if !textToCommit.isEmpty { commit(text: textToCommit) } if !textToCommit.isEmpty { commit(text: textToCommit) }
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
@ -69,27 +69,27 @@ extension ctlInputMethod {
show(tooltip: state.tooltip) show(tooltip: state.tooltip)
} }
case .ofMarking: case .ofMarking:
ctlInputMethod.ctlCandidateCurrent.visible = false Self.ctlCandidateCurrent.visible = false
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
if state.tooltip.isEmpty { if state.tooltip.isEmpty {
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
} else { } else {
show(tooltip: state.tooltip) show(tooltip: state.tooltip)
} }
case .ofCandidates, .ofAssociates, .ofSymbolTable: case .ofCandidates, .ofAssociates, .ofSymbolTable:
ctlInputMethod.tooltipInstance.hide() Self.tooltipInstance.hide()
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
showCandidates() showCandidates()
default: break default: break
} }
// //
if state.hasComposition, PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) { if state.hasComposition, PrefMgr.shared.clientsIMKTextInputIncapable.contains(clientBundleIdentifier) {
ctlInputMethod.popupCompositionBuffer.isTypingDirectionVertical = isVerticalTyping Self.popupCompositionBuffer.isTypingDirectionVertical = isVerticalTyping
ctlInputMethod.popupCompositionBuffer.show( Self.popupCompositionBuffer.show(
state: state, at: lineHeightRect(zeroCursor: true).origin state: state, at: lineHeightRect(zeroCursor: true).origin
) )
} else { } else {
ctlInputMethod.popupCompositionBuffer.hide() Self.popupCompositionBuffer.hide()
} }
} }