KeyHandler // Suppressing EmptyIgnoringPreviousState().

This commit is contained in:
ShikiSuen 2022-07-31 21:40:19 +08:00
parent 7d6ac3cd5f
commit 7ea221f7ec
4 changed files with 31 additions and 13 deletions

View File

@ -69,6 +69,7 @@ extension KeyHandler {
// compositor.isEmpty // compositor.isEmpty
clear() clear()
stateCallback(InputState.EmptyIgnoringPreviousState()) stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
} else { } else {
stateCallback(buildInputtingState) stateCallback(buildInputtingState)
} }
@ -84,6 +85,7 @@ extension KeyHandler {
if state is InputState.AssociatedPhrases, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter { if state is InputState.AssociatedPhrases, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter {
clear() clear()
stateCallback(InputState.EmptyIgnoringPreviousState()) stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
return true return true
} }
delegate?.keyHandler( delegate?.keyHandler(
@ -350,10 +352,10 @@ extension KeyHandler {
ctlCandidate: ctlCandidateCurrent ctlCandidate: ctlCandidateCurrent
) )
clear() clear()
let empty = InputState.EmptyIgnoringPreviousState() stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(empty) stateCallback(InputState.Empty())
return handle( return handle(
input: input, state: empty, stateCallback: stateCallback, errorCallback: errorCallback input: input, state: InputState.Empty(), stateCallback: stateCallback, errorCallback: errorCallback
) )
} }
return true return true

View File

@ -30,18 +30,14 @@ extension KeyHandler {
/// KeyHandler.HandleInput() /// KeyHandler.HandleInput()
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - state:
/// - stateCallback: /// - stateCallback:
/// - errorCallback: /// - errorCallback:
/// - Returns: IMK /// - Returns: IMK
func handleComposition( func handleComposition(
input: InputSignal, input: InputSignal,
state: InputStateProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void, stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void errorCallback: @escaping () -> Void
) -> Bool? { ) -> Bool? {
guard [.ofInputting, .ofEmpty, .ofEmptyIgnoringPreviousState].contains(state.type) else { return nil }
// MARK: (Handle BPMF Keys) // MARK: (Handle BPMF Keys)
var keyConsumedByReading = false var keyConsumedByReading = false
@ -84,7 +80,12 @@ extension KeyHandler {
errorCallback() errorCallback()
composer.clear() composer.clear()
// //
stateCallback((compositor.isEmpty) ? InputState.EmptyIgnoringPreviousState() : buildInputtingState) switch compositor.isEmpty {
case false: stateCallback(buildInputtingState)
case true:
stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
}
return true // IMK return true // IMK
} }

View File

@ -159,7 +159,7 @@ extension KeyHandler {
// MARK: (Handle BPMF Keys) // MARK: (Handle BPMF Keys)
if let compositionHandled = handleComposition( if let compositionHandled = handleComposition(
input: input, state: state, stateCallback: stateCallback, errorCallback: errorCallback input: input, stateCallback: stateCallback, errorCallback: errorCallback
) { ) {
return compositionHandled return compositionHandled
} }

View File

@ -419,8 +419,12 @@ extension KeyHandler {
composer.doBackSpace() composer.doBackSpace()
} }
stateCallback( switch composer.isEmpty && compositor.isEmpty {
composer.isEmpty && compositor.isEmpty ? InputState.EmptyIgnoringPreviousState() : buildInputtingState) case false: stateCallback(buildInputtingState)
case true:
stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
}
return true return true
} }
@ -457,7 +461,12 @@ extension KeyHandler {
walk() walk()
let inputting = buildInputtingState let inputting = buildInputtingState
// count > 0!isEmpty滿 // count > 0!isEmpty滿
stateCallback(inputting.composingBuffer.isEmpty ? InputState.EmptyIgnoringPreviousState() : inputting) switch inputting.composingBuffer.isEmpty {
case false: stateCallback(inputting)
case true:
stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
}
return true return true
} }
@ -569,11 +578,17 @@ extension KeyHandler {
/// macOS Windows 使 /// macOS Windows 使
clear() clear()
stateCallback(InputState.EmptyIgnoringPreviousState()) stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
} else { } else {
if composer.isEmpty { return true } if composer.isEmpty { return true }
/// ///
composer.clear() composer.clear()
stateCallback(compositor.isEmpty ? InputState.EmptyIgnoringPreviousState() : buildInputtingState) switch compositor.isEmpty {
case false: stateCallback(buildInputtingState)
case true:
stateCallback(InputState.EmptyIgnoringPreviousState())
stateCallback(InputState.Empty())
}
} }
return true return true
} }