KeyHandler // Suppressing EmptyIgnoringPreviousState().
This commit is contained in:
parent
7d6ac3cd5f
commit
7ea221f7ec
|
@ -69,6 +69,7 @@ extension KeyHandler {
|
|||
// 所以這裡需要對 compositor.isEmpty 做判定。
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
} else {
|
||||
stateCallback(buildInputtingState)
|
||||
}
|
||||
|
@ -84,6 +85,7 @@ extension KeyHandler {
|
|||
if state is InputState.AssociatedPhrases, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter {
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
}
|
||||
delegate?.keyHandler(
|
||||
|
@ -350,10 +352,10 @@ extension KeyHandler {
|
|||
ctlCandidate: ctlCandidateCurrent
|
||||
)
|
||||
clear()
|
||||
let empty = InputState.EmptyIgnoringPreviousState()
|
||||
stateCallback(empty)
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
return handle(
|
||||
input: input, state: empty, stateCallback: stateCallback, errorCallback: errorCallback
|
||||
input: input, state: InputState.Empty(), stateCallback: stateCallback, errorCallback: errorCallback
|
||||
)
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -30,18 +30,14 @@ extension KeyHandler {
|
|||
/// 用來處理 KeyHandler.HandleInput() 當中的與組字有關的行為。
|
||||
/// - Parameters:
|
||||
/// - input: 輸入訊號。
|
||||
/// - state: 給定狀態(通常為當前狀態)。
|
||||
/// - stateCallback: 狀態回呼,交給對應的型別內的專有函式來處理。
|
||||
/// - errorCallback: 錯誤回呼。
|
||||
/// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。
|
||||
func handleComposition(
|
||||
input: InputSignal,
|
||||
state: InputStateProtocol,
|
||||
stateCallback: @escaping (InputStateProtocol) -> Void,
|
||||
errorCallback: @escaping () -> Void
|
||||
) -> Bool? {
|
||||
guard [.ofInputting, .ofEmpty, .ofEmptyIgnoringPreviousState].contains(state.type) else { return nil }
|
||||
|
||||
// MARK: 注音按鍵輸入處理 (Handle BPMF Keys)
|
||||
|
||||
var keyConsumedByReading = false
|
||||
|
@ -84,7 +80,12 @@ extension KeyHandler {
|
|||
errorCallback()
|
||||
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 報告說這個按鍵訊號已經被輸入法攔截處理了。
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ extension KeyHandler {
|
|||
// MARK: 注音按鍵輸入處理 (Handle BPMF Keys)
|
||||
|
||||
if let compositionHandled = handleComposition(
|
||||
input: input, state: state, stateCallback: stateCallback, errorCallback: errorCallback
|
||||
input: input, stateCallback: stateCallback, errorCallback: errorCallback
|
||||
) {
|
||||
return compositionHandled
|
||||
}
|
||||
|
|
|
@ -419,8 +419,12 @@ extension KeyHandler {
|
|||
composer.doBackSpace()
|
||||
}
|
||||
|
||||
stateCallback(
|
||||
composer.isEmpty && compositor.isEmpty ? InputState.EmptyIgnoringPreviousState() : buildInputtingState)
|
||||
switch composer.isEmpty && compositor.isEmpty {
|
||||
case false: stateCallback(buildInputtingState)
|
||||
case true:
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -457,7 +461,12 @@ extension KeyHandler {
|
|||
walk()
|
||||
let inputting = buildInputtingState
|
||||
// 這裡不用「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
|
||||
}
|
||||
|
||||
|
@ -569,11 +578,17 @@ extension KeyHandler {
|
|||
/// 此乃 macOS 內建注音輸入法預設之行為,但不太受 Windows 使用者群體之待見。
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
} else {
|
||||
if composer.isEmpty { return true }
|
||||
/// 如果注拼槽不是空的話,則清空之。
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue