KeyHandler // Improve behaviors of Delete & BackSpace.

- Allow using Delete to clear composer.
- Allow using Shift+BkSp/Delete to clear compositor.
This commit is contained in:
ShikiSuen 2022-08-06 15:59:13 +08:00
parent c7f218ae93
commit d09b2e6d0d
2 changed files with 25 additions and 9 deletions

View File

@ -259,13 +259,13 @@ extension KeyHandler {
// MARK: Backspace
if input.isBackSpace {
return handleBackSpace(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
return handleBackSpace(state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback)
}
// MARK: Delete
if input.isDelete || input.emacsKey == EmacsKey.delete {
return handleDelete(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
return handleDelete(state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback)
}
// MARK: Enter

View File

@ -381,16 +381,25 @@ extension KeyHandler {
/// Backspace (macOS Delete)
/// - Parameters:
/// - state:
/// - input:
/// - stateCallback:
/// - errorCallback:
/// - Returns: ctlInputMethod IMK
func handleBackSpace(
state: InputStateProtocol,
input: InputSignal,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
guard state is InputState.Inputting else { return false }
if input.isShiftHold {
clear()
stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
return true
}
if composer.hasToneMarker(withNothingElse: true) {
composer.clear()
} else if composer.isEmpty {
@ -421,32 +430,39 @@ extension KeyHandler {
/// PC Delete (macOS Fn+BackSpace)
/// - Parameters:
/// - state:
/// - input:
/// - stateCallback:
/// - errorCallback:
/// - Returns: ctlInputMethod IMK
func handleDelete(
state: InputStateProtocol,
input: InputSignal,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
guard state is InputState.Inputting else { return false }
guard composer.isEmpty else {
IME.prtDebugIntel("9C69908D")
errorCallback()
stateCallback(state)
if input.isShiftHold {
clear()
stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
return true
}
guard compositor.cursor != compositor.length else {
if compositor.cursor == compositor.length, composer.isEmpty {
IME.prtDebugIntel("9B69938D")
errorCallback()
stateCallback(state)
return true
}
if composer.isEmpty {
compositor.dropReading(direction: .front)
walk()
} else {
composer.clear()
}
let inputting = buildInputtingState
// count > 0!isEmpty滿
switch inputting.composingBuffer.isEmpty {