Repo // Simplify certain naming methods.
This commit is contained in:
parent
e9137b9e53
commit
5815a49359
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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, *) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue