InputHandler // + handleNumPadKeyInput().

This commit is contained in:
ShikiSuen 2024-01-28 17:06:33 +08:00
parent ffd64bd7a8
commit 782f3bd21c
2 changed files with 29 additions and 11 deletions

View File

@ -1043,11 +1043,9 @@ extension InputHandler {
delegate.switchState(IMEState.ofEmpty()) delegate.switchState(IMEState.ofEmpty())
// Shift // Shift
if (input.isUpperCaseASCIILetterKey && delegate.isASCIIMode) var shiftCapsLockHandling = input.isUpperCaseASCIILetterKey && delegate.isASCIIMode
|| (handleCapsLock && input.isShiftHold) shiftCapsLockHandling = shiftCapsLockHandling || handleCapsLock && input.isShiftHold
{ guard !shiftCapsLockHandling else { return false }
return false
}
// Shift // Shift
if delegate.isASCIIMode, !handleCapsLock { return false } if delegate.isASCIIMode, !handleCapsLock { return false }
@ -1143,6 +1141,31 @@ extension InputHandler {
return false return false
} }
// MARK: - NumPad
///
/// - Parameter input:
/// - Returns: IMK
func handleNumPadKeyInput(input: InputSignalProtocol) -> Bool {
guard let delegate = delegate, input.isNumericPadKey else { return false }
let inputText = input.text
guard inputText.count == 1, input.isASCII else { return false }
guard KeyCode(rawValue: input.keyCode) == nil else { return false } //
let behaviorValue = prefs.numPadCharInputBehavior
let fullWidthResult = behaviorValue % 2 != 0 //
triagePrefs: switch (behaviorValue, isConsideredEmptyForNow) {
case (2, _), (3, _), (4, false), (5, false):
currentLM.config.numPadFWHWStatus = fullWidthResult
if handlePunctuation("_NumPad_\(inputText)") { return true }
default: break triagePrefs // case 0 & 1
}
currentLM.config.numPadFWHWStatus = nil
delegate.switchState(IMEState.ofEmpty())
let charToCommit = inputText.applyingTransformFW2HW(reverse: fullWidthResult)
delegate.switchState(IMEState.ofCommitting(textToCommit: charToCommit))
return true
}
// MARK: - // MARK: -
func handleCassetteSymbolTable(input: InputSignalProtocol) -> Bool { func handleCassetteSymbolTable(input: InputSignalProtocol) -> Bool {

View File

@ -22,7 +22,6 @@ public extension InputHandler {
func triageInput(event input: InputSignalProtocol) -> Bool { func triageInput(event input: InputSignalProtocol) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
var state: IMEStateProtocol { delegate.state } var state: IMEStateProtocol { delegate.state }
let inputText = input.text
// MARK: - Triage by KeyCode // MARK: - Triage by KeyCode
@ -142,11 +141,7 @@ public extension InputHandler {
} }
// //
if input.isNumericPadKey { if handleNumPadKeyInput(input: input) { return true }
delegate.switchState(IMEState.ofEmpty())
delegate.switchState(IMEState.ofCommitting(textToCommit: inputText.lowercased()))
return true
}
// //
haninSymbolInput: if prefs.classicHaninKeyboardSymbolModeShortcutEnabled { haninSymbolInput: if prefs.classicHaninKeyboardSymbolModeShortcutEnabled {