KeyHandler // Suppressing EmptyIgnoringPreviousState().
This commit is contained in:
parent
7d6ac3cd5f
commit
7ea221f7ec
|
@ -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
|
||||||
|
|
|
@ -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 報告說這個按鍵訊號已經被輸入法攔截處理了。
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue