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

View File

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

View File

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

View File

@ -143,7 +143,7 @@ extension ctlInputMethod {
// interpretKeyEvents()
// - imkCandidates.interpretKeyEvents()
// - 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
// Shift+Enter delegate keyHandler
@ -206,7 +206,7 @@ extension ctlInputMethod {
let newEvent = event.reinitiate(characters: newChar)
if let newEvent = newEvent {
if PrefMgr.shared.useSCPCTypingMode, state.type == .ofAssociates {
// input.isShiftHold ctlInputMethod.handle()
// input.isShiftHold Self.handle()
return event.isShiftHold ? true : commonEventHandler(event)
} else {
if #available(macOS 10.14, *) {

View File

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