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:
parent
c7f218ae93
commit
d09b2e6d0d
|
@ -259,13 +259,13 @@ extension KeyHandler {
|
||||||
// MARK: Backspace
|
// MARK: Backspace
|
||||||
|
|
||||||
if input.isBackSpace {
|
if input.isBackSpace {
|
||||||
return handleBackSpace(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
|
return handleBackSpace(state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Delete
|
// MARK: Delete
|
||||||
|
|
||||||
if input.isDelete || input.emacsKey == EmacsKey.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
|
// MARK: Enter
|
||||||
|
|
|
@ -381,16 +381,25 @@ extension KeyHandler {
|
||||||
/// 處理 Backspace (macOS Delete) 按鍵行為。
|
/// 處理 Backspace (macOS Delete) 按鍵行為。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - state: 當前狀態。
|
/// - state: 當前狀態。
|
||||||
|
/// - input: 輸入按鍵訊號。
|
||||||
/// - stateCallback: 狀態回呼。
|
/// - stateCallback: 狀態回呼。
|
||||||
/// - errorCallback: 錯誤回呼。
|
/// - errorCallback: 錯誤回呼。
|
||||||
/// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。
|
/// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。
|
||||||
func handleBackSpace(
|
func handleBackSpace(
|
||||||
state: InputStateProtocol,
|
state: InputStateProtocol,
|
||||||
|
input: InputSignal,
|
||||||
stateCallback: @escaping (InputStateProtocol) -> Void,
|
stateCallback: @escaping (InputStateProtocol) -> Void,
|
||||||
errorCallback: @escaping () -> Void
|
errorCallback: @escaping () -> Void
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
guard state is InputState.Inputting else { return false }
|
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) {
|
if composer.hasToneMarker(withNothingElse: true) {
|
||||||
composer.clear()
|
composer.clear()
|
||||||
} else if composer.isEmpty {
|
} else if composer.isEmpty {
|
||||||
|
@ -421,32 +430,39 @@ extension KeyHandler {
|
||||||
/// 處理 PC Delete (macOS Fn+BackSpace) 按鍵行為。
|
/// 處理 PC Delete (macOS Fn+BackSpace) 按鍵行為。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - state: 當前狀態。
|
/// - state: 當前狀態。
|
||||||
|
/// - input: 輸入按鍵訊號。
|
||||||
/// - stateCallback: 狀態回呼。
|
/// - stateCallback: 狀態回呼。
|
||||||
/// - errorCallback: 錯誤回呼。
|
/// - errorCallback: 錯誤回呼。
|
||||||
/// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。
|
/// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。
|
||||||
func handleDelete(
|
func handleDelete(
|
||||||
state: InputStateProtocol,
|
state: InputStateProtocol,
|
||||||
|
input: InputSignal,
|
||||||
stateCallback: @escaping (InputStateProtocol) -> Void,
|
stateCallback: @escaping (InputStateProtocol) -> Void,
|
||||||
errorCallback: @escaping () -> Void
|
errorCallback: @escaping () -> Void
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
guard state is InputState.Inputting else { return false }
|
guard state is InputState.Inputting else { return false }
|
||||||
|
|
||||||
guard composer.isEmpty else {
|
if input.isShiftHold {
|
||||||
IME.prtDebugIntel("9C69908D")
|
clear()
|
||||||
errorCallback()
|
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||||
stateCallback(state)
|
stateCallback(InputState.Empty())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
guard compositor.cursor != compositor.length else {
|
if compositor.cursor == compositor.length, composer.isEmpty {
|
||||||
IME.prtDebugIntel("9B69938D")
|
IME.prtDebugIntel("9B69938D")
|
||||||
errorCallback()
|
errorCallback()
|
||||||
stateCallback(state)
|
stateCallback(state)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
compositor.dropReading(direction: .front)
|
if composer.isEmpty {
|
||||||
walk()
|
compositor.dropReading(direction: .front)
|
||||||
|
walk()
|
||||||
|
} else {
|
||||||
|
composer.clear()
|
||||||
|
}
|
||||||
|
|
||||||
let inputting = buildInputtingState
|
let inputting = buildInputtingState
|
||||||
// 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。
|
// 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。
|
||||||
switch inputting.composingBuffer.isEmpty {
|
switch inputting.composingBuffer.isEmpty {
|
||||||
|
|
Loading…
Reference in New Issue