IMEState // Ensure lowerCamelCase.

This commit is contained in:
ShikiSuen 2022-09-05 17:51:03 +08:00
parent 75193a32fd
commit e85e3382fe
8 changed files with 85 additions and 85 deletions

View File

@ -51,7 +51,7 @@ public protocol IMEStateProtocol {
///
///
/// IMEState
/// IMEState.Marking IMEState.Inputting
/// IMEState.ofMarking IMEState.ofInputting
///
/// (Constructor)
///
@ -91,23 +91,23 @@ public struct IMEState: IMEStateProtocol {
// MARK: -
extension IMEState {
public static func Deactivated() -> IMEState { .init(type: .ofDeactivated) }
public static func Empty() -> IMEState { .init(type: .ofEmpty) }
public static func Abortion() -> IMEState { .init(type: .ofAbortion) }
public static func Committing(textToCommit: String) -> IMEState {
public static func ofDeactivated() -> IMEState { .init(type: .ofDeactivated) }
public static func ofEmpty() -> IMEState { .init(type: .ofEmpty) }
public static func ofAbortion() -> IMEState { .init(type: .ofAbortion) }
public static func ofCommitting(textToCommit: String) -> IMEState {
var result = IMEState(type: .ofCommitting)
result.data.textToCommit = textToCommit
ChineseConverter.ensureCurrencyNumerals(target: &result.data.textToCommit)
return result
}
public static func Associates(candidates: [(String, String)]) -> IMEState {
public static func ofAssociates(candidates: [(String, String)]) -> IMEState {
var result = IMEState(type: .ofAssociates)
result.data.candidates = candidates
return result
}
public static func NotEmpty(displayTextSegments: [String], cursor: Int) -> IMEState {
public static func ofNotEmpty(displayTextSegments: [String], cursor: Int) -> IMEState {
var result = IMEState(type: .ofNotEmpty)
// displayTextSegments
result.data.displayTextSegments = displayTextSegments
@ -115,18 +115,18 @@ extension IMEState {
return result
}
public static func Inputting(displayTextSegments: [String], cursor: Int) -> IMEState {
var result = IMEState.NotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
public static func ofInputting(displayTextSegments: [String], cursor: Int) -> IMEState {
var result = IMEState.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofInputting
return result
}
public static func Marking(
public static func ofMarking(
displayTextSegments: [String], markedReadings: [String], cursor: Int, marker: Int
)
-> IMEState
{
var result = IMEState.NotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
var result = IMEState.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofMarking
result.data.marker = marker
result.data.markedReadings = markedReadings
@ -134,15 +134,15 @@ extension IMEState {
return result
}
public static func Candidates(candidates: [(String, String)], displayTextSegments: [String], cursor: Int) -> IMEState
public static func ofCandidates(candidates: [(String, String)], displayTextSegments: [String], cursor: Int) -> IMEState
{
var result = IMEState.NotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
var result = IMEState.ofNotEmpty(displayTextSegments: displayTextSegments, cursor: cursor)
result.type = .ofCandidates
result.data.candidates = candidates
return result
}
public static func SymbolTable(node: SymbolNode) -> IMEState {
public static func ofSymbolTable(node: SymbolNode) -> IMEState {
var result = IMEState(type: .ofNotEmpty, node: node)
result.type = .ofSymbolTable
return result
@ -156,7 +156,7 @@ extension IMEState {
public var candidates: [(String, String)] { data.candidates }
public var convertedToInputting: IMEState {
if type == .ofInputting { return self }
var result = IMEState.Inputting(displayTextSegments: data.displayTextSegments, cursor: data.cursor)
var result = IMEState.ofInputting(displayTextSegments: data.displayTextSegments, cursor: data.cursor)
result.tooltip = data.tooltipBackupForInputting
return result
}

View File

@ -49,12 +49,12 @@ extension KeyHandler {
//
// 使 BackSpace
// compositor.isEmpty
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
} else {
stateCallback(buildInputtingState)
}
if state.type == .ofSymbolTable, let nodePrevious = state.node.previous, let _ = nodePrevious.children {
stateCallback(IMEState.SymbolTable(node: nodePrevious))
stateCallback(IMEState.ofSymbolTable(node: nodePrevious))
}
return true
}
@ -63,7 +63,7 @@ extension KeyHandler {
if input.isEnter {
if state.type == .ofAssociates, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter {
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
return true
}
delegate?.keyHandler(
@ -323,9 +323,9 @@ extension KeyHandler {
didSelectCandidateAt: candidateIndex,
ctlCandidate: ctlCandidateCurrent
)
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
return handle(
input: input, state: IMEState.Empty(), stateCallback: stateCallback, errorCallback: errorCallback
input: input, state: IMEState.ofEmpty(), stateCallback: stateCallback, errorCallback: errorCallback
)
}
return true

View File

@ -100,7 +100,7 @@ extension KeyHandler {
switch compositor.isEmpty {
case false: stateCallback(buildInputtingState)
case true:
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
}
return true // IMK
}
@ -130,16 +130,16 @@ extension KeyHandler {
if candidateState.candidates.count == 1, let firstCandidate = candidateState.candidates.first {
let reading: String = firstCandidate.0
let text: String = firstCandidate.1
stateCallback(IMEState.Committing(textToCommit: text))
stateCallback(IMEState.ofCommitting(textToCommit: text))
if !mgrPrefs.associatedPhrasesEnabled {
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
} else {
let associatedPhrases =
buildAssociatePhraseState(
withPair: .init(key: reading, value: text)
)
stateCallback(associatedPhrases.candidates.isEmpty ? IMEState.Empty() : associatedPhrases)
stateCallback(associatedPhrases.candidates.isEmpty ? IMEState.ofEmpty() : associatedPhrases)
}
} else {
stateCallback(candidateState)

View File

@ -68,7 +68,7 @@ extension KeyHandler {
// BackSpace
} else if input.isCapsLockOn || input.isASCIIModeInput {
//
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
// Shift
if input.isUpperCaseASCIILetterKey {
@ -82,8 +82,8 @@ extension KeyHandler {
}
//
stateCallback(IMEState.Committing(textToCommit: inputText.lowercased()))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: inputText.lowercased()))
stateCallback(IMEState.ofEmpty())
return true
}
@ -97,9 +97,9 @@ extension KeyHandler {
if !(state.type == .ofCandidates || state.type == .ofAssociates
|| state.type == .ofSymbolTable)
{
stateCallback(IMEState.Empty())
stateCallback(IMEState.Committing(textToCommit: inputText.lowercased()))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
stateCallback(IMEState.ofCommitting(textToCommit: inputText.lowercased()))
stateCallback(IMEState.ofEmpty())
return true
}
}
@ -120,7 +120,7 @@ extension KeyHandler {
) {
return true
} else {
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
}
}
@ -157,10 +157,10 @@ extension KeyHandler {
if compositor.cursor >= compositor.length {
let displayedText = state.displayedText
if !displayedText.isEmpty {
stateCallback(IMEState.Committing(textToCommit: displayedText))
stateCallback(IMEState.ofCommitting(textToCommit: displayedText))
}
stateCallback(IMEState.Committing(textToCommit: " "))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: " "))
stateCallback(IMEState.ofEmpty())
} else if currentLM.hasUnigramsFor(key: " ") {
compositor.insertKey(" ")
walk()
@ -297,7 +297,7 @@ extension KeyHandler {
// Enter 使 commit buffer
// bool _ =
_ = handleEnter(state: state, stateCallback: stateCallback)
stateCallback(IMEState.SymbolTable(node: SymbolNode.root))
stateCallback(IMEState.ofSymbolTable(node: SymbolNode.root))
return true
}
}
@ -312,9 +312,9 @@ extension KeyHandler {
let string = NSMutableString(string: stringRAW)
CFStringTransform(string, nil, kCFStringTransformFullwidthHalfwidth, true)
stateCallback(
IMEState.Committing(textToCommit: mgrPrefs.halfWidthPunctuationEnabled ? stringRAW : string as String)
IMEState.ofCommitting(textToCommit: mgrPrefs.halfWidthPunctuationEnabled ? stringRAW : string as String)
)
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
return true
}
}
@ -359,8 +359,8 @@ extension KeyHandler {
/// 使
if state.type == .ofEmpty {
if input.isSpace, !input.isOptionHold, !input.isControlHold, !input.isCommandHold {
stateCallback(IMEState.Committing(textToCommit: input.isShiftHold ? " " : " "))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: input.isShiftHold ? " " : " "))
stateCallback(IMEState.ofEmpty())
return true
}
}
@ -371,14 +371,14 @@ extension KeyHandler {
if input.isShiftHold { // isOptionHold
switch mgrPrefs.upperCaseLetterKeyBehavior {
case 1:
stateCallback(IMEState.Empty())
stateCallback(IMEState.Committing(textToCommit: inputText.lowercased()))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
stateCallback(IMEState.ofCommitting(textToCommit: inputText.lowercased()))
stateCallback(IMEState.ofEmpty())
return true
case 2:
stateCallback(IMEState.Empty())
stateCallback(IMEState.Committing(textToCommit: inputText.uppercased()))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofEmpty())
stateCallback(IMEState.ofCommitting(textToCommit: inputText.uppercased()))
stateCallback(IMEState.ofEmpty())
return true
default: // case 0
let letter = "_letter_\(inputText)"

View File

@ -52,7 +52,7 @@ extension KeyHandler {
cursor += reading.count
}
/// 使
return IMEState.Inputting(displayTextSegments: displayTextSegments, cursor: cursor)
return IMEState.ofInputting(displayTextSegments: displayTextSegments, cursor: cursor)
}
///
@ -97,7 +97,7 @@ extension KeyHandler {
state currentState: IMEStateProtocol,
isTypingVertical _: Bool = false
) -> IMEState {
IMEState.Candidates(
IMEState.ofCandidates(
candidates: getCandidatesArray(fixOrder: mgrPrefs.useFixecCandidateOrderOnSelection),
displayTextSegments: compositor.walkedNodes.values,
cursor: currentState.data.cursor
@ -122,7 +122,7 @@ extension KeyHandler {
withPair pair: Megrez.Compositor.KeyValuePaired
) -> IMEState {
//  Xcode
IMEState.Associates(
IMEState.ofAssociates(
candidates: buildAssociatePhraseArray(withPair: pair))
}
@ -196,7 +196,7 @@ extension KeyHandler {
if isCursorCuttingChar(isMarker: true) {
compositor.jumpCursorBySpan(to: .rear, isMarker: true)
}
var marking = IMEState.Marking(
var marking = IMEState.ofMarking(
displayTextSegments: state.data.displayTextSegments,
markedReadings: Array(compositor.keys[currentMarkedRange()]),
cursor: convertCursorForDisplay(compositor.cursor),
@ -219,7 +219,7 @@ extension KeyHandler {
if isCursorCuttingChar(isMarker: true) {
compositor.jumpCursorBySpan(to: .front, isMarker: true)
}
var marking = IMEState.Marking(
var marking = IMEState.ofMarking(
displayTextSegments: state.data.displayTextSegments,
markedReadings: Array(compositor.keys[currentMarkedRange()]),
cursor: convertCursorForDisplay(compositor.cursor),
@ -281,8 +281,8 @@ extension KeyHandler {
if candidateState.candidates.count == 1 {
clear() // candidateState
if let candidateToCommit: (String, String) = candidateState.candidates.first, !candidateToCommit.1.isEmpty {
stateCallback(IMEState.Committing(textToCommit: candidateToCommit.1))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: candidateToCommit.1))
stateCallback(IMEState.ofEmpty())
} else {
stateCallback(candidateState)
}
@ -305,8 +305,8 @@ extension KeyHandler {
) -> Bool {
guard state.type == .ofInputting else { return false }
stateCallback(IMEState.Committing(textToCommit: state.displayedText))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: state.displayedText))
stateCallback(IMEState.ofEmpty())
return true
}
@ -333,8 +333,8 @@ extension KeyHandler {
displayedText = displayedText.replacingOccurrences(of: "-", with: " ")
}
stateCallback(IMEState.Committing(textToCommit: displayedText))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: displayedText))
stateCallback(IMEState.ofEmpty())
return true
}
@ -369,8 +369,8 @@ extension KeyHandler {
composed += key.contains("_") ? value : "<ruby>\(value)<rp>(</rp><rt>\(key)</rt><rp>)</rp></ruby>"
}
stateCallback(IMEState.Committing(textToCommit: composed))
stateCallback(IMEState.Empty())
stateCallback(IMEState.ofCommitting(textToCommit: composed))
stateCallback(IMEState.ofEmpty())
return true
}
@ -403,13 +403,13 @@ extension KeyHandler {
stateCallback(buildInputtingState)
return true
case 1:
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
return true
default: break
}
if input.isShiftHold, input.isOptionHold {
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
return true
}
@ -432,7 +432,7 @@ extension KeyHandler {
switch composer.isEmpty && compositor.isEmpty {
case false: stateCallback(buildInputtingState)
case true:
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
}
return true
}
@ -455,7 +455,7 @@ extension KeyHandler {
guard state.type == .ofInputting else { return false }
if input.isShiftHold {
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
return true
}
@ -478,7 +478,7 @@ extension KeyHandler {
switch inputting.displayedText.isEmpty {
case false: stateCallback(inputting)
case true:
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
}
return true
}
@ -589,7 +589,7 @@ extension KeyHandler {
if mgrPrefs.escToCleanInputBuffer {
///
/// macOS Windows 使
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
} else {
if composer.isEmpty { return true }
///
@ -597,7 +597,7 @@ extension KeyHandler {
switch compositor.isEmpty {
case false: stateCallback(buildInputtingState)
case true:
stateCallback(IMEState.Abortion())
stateCallback(IMEState.ofAbortion())
}
}
return true
@ -634,7 +634,7 @@ extension KeyHandler {
if isCursorCuttingChar(isMarker: true) {
compositor.jumpCursorBySpan(to: .front, isMarker: true)
}
var marking = IMEState.Marking(
var marking = IMEState.ofMarking(
displayTextSegments: compositor.walkedNodes.values,
markedReadings: Array(compositor.keys[currentMarkedRange()]),
cursor: convertCursorForDisplay(compositor.cursor),
@ -707,7 +707,7 @@ extension KeyHandler {
if isCursorCuttingChar(isMarker: true) {
compositor.jumpCursorBySpan(to: .rear, isMarker: true)
}
var marking = IMEState.Marking(
var marking = IMEState.ofMarking(
displayTextSegments: compositor.walkedNodes.values,
markedReadings: Array(compositor.keys[currentMarkedRange()]),
cursor: convertCursorForDisplay(compositor.cursor),

View File

@ -41,7 +41,7 @@ class ctlInputMethod: IMKInputController {
/// 調
var keyHandler: KeyHandler = .init()
///
var state: IMEStateProtocol = IMEState.Empty() {
var state: IMEStateProtocol = IMEState.ofEmpty() {
didSet {
IME.prtDebugIntel("Current State: \(state.type.rawValue)")
}
@ -75,9 +75,9 @@ class ctlInputMethod: IMKInputController {
}
if state.hasComposition {
/// 調
handle(state: IMEState.Committing(textToCommit: state.displayedText))
handle(state: IMEState.ofCommitting(textToCommit: state.displayedText))
}
handle(state: IMEState.Empty())
handle(state: IMEState.ofEmpty())
}
// MARK: - IMKInputController
@ -131,7 +131,7 @@ class ctlInputMethod: IMKInputController {
if let client = client(), client.bundleIdentifier() != Bundle.main.bundleIdentifier {
// 使
setKeyLayout()
handle(state: IMEState.Empty())
handle(state: IMEState.ofEmpty())
} //
(NSApp.delegate as? AppDelegate)?.checkForUpdate()
}
@ -141,7 +141,7 @@ class ctlInputMethod: IMKInputController {
override func deactivateServer(_ sender: Any!) {
_ = sender //
resetKeyHandler() // Empty
handle(state: IMEState.Deactivated())
handle(state: IMEState.ofDeactivated())
}
///
@ -172,7 +172,7 @@ class ctlInputMethod: IMKInputController {
if let client = client(), client.bundleIdentifier() != Bundle.main.bundleIdentifier {
// 使
setKeyLayout()
handle(state: IMEState.Empty())
handle(state: IMEState.ofEmpty())
} //
}
@ -367,7 +367,7 @@ class ctlInputMethod: IMKInputController {
let candidateString: NSAttributedString = candidateString ?? .init(string: "")
if state.type == .ofAssociates {
if !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter {
handle(state: IMEState.Abortion())
handle(state: IMEState.ofAbortion())
return
}
}

View File

@ -111,11 +111,11 @@ extension ctlInputMethod: ctlCandidateDelegate {
let node = state.node.children?[index]
{
if let children = node.children, !children.isEmpty {
handle(state: IMEState.Empty()) //
handle(state: IMEState.SymbolTable(node: node))
handle(state: IMEState.ofEmpty()) //
handle(state: IMEState.ofSymbolTable(node: node))
} else {
handle(state: IMEState.Committing(textToCommit: node.title))
handle(state: IMEState.Empty())
handle(state: IMEState.ofCommitting(textToCommit: node.title))
handle(state: IMEState.ofEmpty())
}
return
}
@ -130,15 +130,15 @@ extension ctlInputMethod: ctlCandidateDelegate {
let inputting = keyHandler.buildInputtingState
if mgrPrefs.useSCPCTypingMode {
handle(state: IMEState.Committing(textToCommit: inputting.displayedText))
handle(state: IMEState.ofCommitting(textToCommit: inputting.displayedText))
// selectedValue.1
if mgrPrefs.associatedPhrasesEnabled {
let associates = keyHandler.buildAssociatePhraseState(
withPair: .init(key: selectedValue.0, value: selectedValue.1)
)
handle(state: associates.candidates.isEmpty ? IMEState.Empty() : associates)
handle(state: associates.candidates.isEmpty ? IMEState.ofEmpty() : associates)
} else {
handle(state: IMEState.Empty())
handle(state: IMEState.ofEmpty())
}
} else {
handle(state: inputting)
@ -148,11 +148,11 @@ extension ctlInputMethod: ctlCandidateDelegate {
if state.type == .ofAssociates {
let selectedValue = state.candidates[index]
handle(state: IMEState.Committing(textToCommit: selectedValue.1))
handle(state: IMEState.ofCommitting(textToCommit: selectedValue.1))
// selectedValue.1
//
guard let valueKept = selectedValue.1.last else {
handle(state: IMEState.Empty())
handle(state: IMEState.ofEmpty())
return
}
if mgrPrefs.associatedPhrasesEnabled {
@ -164,7 +164,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
return
}
}
handle(state: IMEState.Empty())
handle(state: IMEState.ofEmpty())
}
}
}

View File

@ -35,7 +35,7 @@ extension ctlInputMethod {
case .ofEmpty, .ofAbortion:
var previous = previous
if state.type == .ofAbortion {
state = IMEState.Empty()
state = IMEState.ofEmpty()
previous = state
}
ctlInputMethod.ctlCandidateCurrent.visible = false