InputHandler // Extract handlePunctuationList(), etc.

* Also fix an issue which commits unfinished composer / calligrapher contents.
This commit is contained in:
ShikiSuen 2023-02-08 15:17:28 +08:00
parent 2cdc64b1ff
commit ab9702b6a8
2 changed files with 55 additions and 39 deletions

View File

@ -157,6 +157,15 @@ extension InputHandler {
case .kBackSpace: return handleBackSpace(input: input)
case .kWindowsDelete: return handleDelete(input: input)
case .kCarriageReturn, .kLineFeed: return handleEnter(input: input)
case .kSymbolMenuPhysicalKeyJIS, .kSymbolMenuPhysicalKeyIntl:
let isJIS = keyCodeType == .kSymbolMenuPhysicalKeyJIS
switch input.modifierFlags {
case []:
return handlePunctuationList(alternative: false, isJIS: isJIS)
case [.option]:
return handlePunctuationList(alternative: true, isJIS: isJIS)
default: break
}
case .kSpace: // Space
//
switch state.type {
@ -191,45 +200,6 @@ extension InputHandler {
}
}
// MARK: Punctuation list
if input.isSymbolMenuPhysicalKey, !input.isShiftHold, !input.isControlHold, state.type != .ofDeactivated {
if input.isOptionHold {
if currentLM.hasUnigramsFor(keyArray: ["_punctuation_list"]) {
if isComposerOrCalligrapherEmpty, compositor.insertKey("_punctuation_list") {
walk()
// App
let textToCommit = commitOverflownComposition
var inputting = generateStateOfInputting()
inputting.textToCommit = textToCommit
delegate.switchState(inputting)
//
let newState = generateStateOfCandidates()
_ = newState.candidates.isEmpty ? delegate.callError("B5127D8A") : delegate.switchState(newState)
} else { //
delegate.callError("17446655")
}
return true
} else {
let errorMessage =
NSLocalizedString(
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key.",
comment: ""
)
vCLog("8EB3FB1A: " + errorMessage)
delegate.switchState(IMEState.ofEmpty())
let isJIS: Bool = input.keyCode == KeyCode.kSymbolMenuPhysicalKeyJIS.rawValue
delegate.switchState(IMEState.ofCommitting(textToCommit: isJIS ? "_" : "`"))
return true
}
} else {
// commit buffer ESC
delegate.switchState(IMEState.ofCommitting(textToCommit: state.displayedText))
delegate.switchState(IMEState.ofSymbolTable(node: CandidateNode.root))
return true
}
}
// MARK: / (FW / HW Arabic Numbers Input)
if state.type == .ofEmpty {

View File

@ -762,4 +762,50 @@ extension InputHandler {
delegate.switchState(newState)
return true
}
// MARK: -
///
/// - Parameters:
/// - alternative: 使
/// - JIS: JIS
/// - Returns: SessionCtl IMK
func handlePunctuationList(alternative: Bool, isJIS: Bool = false) -> Bool {
guard let delegate = delegate, delegate.state.type != .ofDeactivated else { return false }
if alternative {
if currentLM.hasUnigramsFor(keyArray: ["_punctuation_list"]) {
if isComposerOrCalligrapherEmpty, compositor.insertKey("_punctuation_list") {
walk()
// App
let textToCommit = commitOverflownComposition
var inputting = generateStateOfInputting()
inputting.textToCommit = textToCommit
delegate.switchState(inputting)
//
let newState = generateStateOfCandidates()
_ = newState.candidates.isEmpty ? delegate.callError("B5127D8A") : delegate.switchState(newState)
} else { //
delegate.callError("17446655")
}
return true
} else {
let errorMessage =
NSLocalizedString(
"Please manually implement the symbols of this menu \nin the user phrase file with “_punctuation_list” key.",
comment: ""
)
vCLog("8EB3FB1A: " + errorMessage)
let textToCommit = generateStateOfInputting(sansReading: true).displayedText
delegate.switchState(IMEState.ofCommitting(textToCommit: textToCommit))
delegate.switchState(IMEState.ofCommitting(textToCommit: isJIS ? "_" : "`"))
return true
}
} else {
// commit buffer ESC
let textToCommit = generateStateOfInputting(sansReading: true).displayedText
delegate.switchState(IMEState.ofCommitting(textToCommit: textToCommit))
delegate.switchState(IMEState.ofSymbolTable(node: CandidateNode.root))
return true
}
}
}