Repo // Tidy-up all usage scenarios of keyHandler.clear().
This commit is contained in:
parent
02e312d3f4
commit
c406d70584
|
@ -51,7 +51,6 @@ extension KeyHandler {
|
|||
// 就將當前的組字緩衝區析構處理、強制重設輸入狀態。
|
||||
// 否則,一個本不該出現的真空組字緩衝區會使前後方向鍵與 BackSpace 鍵失靈。
|
||||
// 所以這裡需要對 compositor.isEmpty 做判定。
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
} else {
|
||||
|
@ -67,7 +66,6 @@ extension KeyHandler {
|
|||
|
||||
if input.isEnter {
|
||||
if state is InputState.AssociatedPhrases, !mgrPrefs.alsoConfirmAssociatedCandidatesByEnter {
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
|
@ -335,7 +333,6 @@ extension KeyHandler {
|
|||
didSelectCandidateAt: candidateIndex,
|
||||
ctlCandidate: ctlCandidateCurrent
|
||||
)
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
return handle(
|
||||
|
|
|
@ -107,7 +107,6 @@ extension KeyHandler {
|
|||
isTypingVertical: input.isTypingVertical
|
||||
)
|
||||
if choosingCandidates.candidates.count == 1 {
|
||||
clear()
|
||||
let reading: String = choosingCandidates.candidates.first?.0 ?? ""
|
||||
let text: String = choosingCandidates.candidates.first?.1 ?? ""
|
||||
stateCallback(InputState.Committing(textToCommit: text))
|
||||
|
|
|
@ -69,7 +69,6 @@ extension KeyHandler {
|
|||
// 略過對 BackSpace 的處理。
|
||||
} else if input.isCapsLockOn || input.isASCIIModeInput {
|
||||
// 但願能夠處理這種情況下所有可能的按鍵組合。
|
||||
clear()
|
||||
stateCallback(InputState.Empty())
|
||||
|
||||
// 摁 Shift 的話,無須額外處理,因為直接就會敲出大寫字母。
|
||||
|
@ -99,7 +98,6 @@ extension KeyHandler {
|
|||
if !(state is InputState.ChoosingCandidate || state is InputState.AssociatedPhrases
|
||||
|| state is InputState.SymbolTable)
|
||||
{
|
||||
clear()
|
||||
stateCallback(InputState.Empty())
|
||||
stateCallback(InputState.Committing(textToCommit: inputText.lowercased()))
|
||||
stateCallback(InputState.Empty())
|
||||
|
@ -162,7 +160,6 @@ extension KeyHandler {
|
|||
if !composingBuffer.isEmpty {
|
||||
stateCallback(InputState.Committing(textToCommit: composingBuffer))
|
||||
}
|
||||
clear()
|
||||
stateCallback(InputState.Committing(textToCommit: " "))
|
||||
stateCallback(InputState.Empty())
|
||||
} else if currentLM.hasUnigramsFor(key: " ") {
|
||||
|
|
|
@ -276,7 +276,7 @@ extension KeyHandler {
|
|||
isTypingVertical: isTypingVertical
|
||||
)
|
||||
if candidateState.candidates.count == 1 {
|
||||
clear()
|
||||
clear() // 這句不要砍,因為下文可能會回呼 candidateState。
|
||||
if let candidateToCommit: (String, String) = candidateState.candidates.first, !candidateToCommit.1.isEmpty {
|
||||
stateCallback(InputState.Committing(textToCommit: candidateToCommit.1))
|
||||
stateCallback(InputState.Empty())
|
||||
|
@ -302,7 +302,6 @@ extension KeyHandler {
|
|||
) -> Bool {
|
||||
guard let currentState = state as? InputState.Inputting else { return false }
|
||||
|
||||
clear()
|
||||
stateCallback(InputState.Committing(textToCommit: currentState.composingBuffer))
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
|
@ -331,8 +330,6 @@ extension KeyHandler {
|
|||
composingBuffer = composingBuffer.replacingOccurrences(of: "-", with: " ")
|
||||
}
|
||||
|
||||
clear()
|
||||
|
||||
stateCallback(InputState.Committing(textToCommit: composingBuffer))
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
|
@ -369,8 +366,6 @@ extension KeyHandler {
|
|||
composed += key.contains("_") ? value : "<ruby>\(value)<rp>(</rp><rt>\(key)</rt><rp>)</rp></ruby>"
|
||||
}
|
||||
|
||||
clear()
|
||||
|
||||
stateCallback(InputState.Committing(textToCommit: composed))
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
|
@ -394,7 +389,6 @@ extension KeyHandler {
|
|||
guard state is InputState.Inputting else { return false }
|
||||
|
||||
if input.isShiftHold {
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
|
@ -443,7 +437,6 @@ extension KeyHandler {
|
|||
guard state is InputState.Inputting else { return false }
|
||||
|
||||
if input.isShiftHold {
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
return true
|
||||
|
@ -580,7 +573,6 @@ extension KeyHandler {
|
|||
if mgrPrefs.escToCleanInputBuffer {
|
||||
/// 若啟用了該選項,則清空組字器的內容與注拼槽的內容。
|
||||
/// 此乃 macOS 內建注音輸入法預設之行為,但不太受 Windows 使用者群體之待見。
|
||||
clear()
|
||||
stateCallback(InputState.EmptyIgnoringPreviousState())
|
||||
stateCallback(InputState.Empty())
|
||||
} else {
|
||||
|
|
|
@ -62,7 +62,6 @@ class ctlInputMethod: IMKInputController {
|
|||
/// 將傳回的新狀態交給調度函式。
|
||||
handle(state: InputState.Committing(textToCommit: state.composingBufferConverted))
|
||||
}
|
||||
keyHandler.clear()
|
||||
handle(state: InputState.Empty())
|
||||
}
|
||||
|
||||
|
@ -96,7 +95,7 @@ class ctlInputMethod: IMKInputController {
|
|||
// 所以這裡添加這句、來試圖應對這種情況。
|
||||
if keyHandler.delegate == nil { keyHandler.delegate = self }
|
||||
setValue(IME.currentInputMode.rawValue, forTag: 114_514, client: client())
|
||||
keyHandler.clear()
|
||||
keyHandler.clear() // 這句不要砍,因為後面 handle State.Empty() 不一定執行。
|
||||
keyHandler.ensureParser()
|
||||
|
||||
if isASCIIMode {
|
||||
|
@ -123,7 +122,6 @@ class ctlInputMethod: IMKInputController {
|
|||
/// - Parameter sender: 呼叫了該函式的客體(無須使用)。
|
||||
override func deactivateServer(_ sender: Any!) {
|
||||
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
||||
keyHandler.clear()
|
||||
handle(state: InputState.Empty())
|
||||
handle(state: InputState.Deactivated())
|
||||
}
|
||||
|
@ -149,7 +147,7 @@ class ctlInputMethod: IMKInputController {
|
|||
|
||||
if keyHandler.inputMode != newInputMode {
|
||||
UserDefaults.standard.synchronize()
|
||||
keyHandler.clear()
|
||||
keyHandler.clear() // 這句不要砍,因為後面 handle State.Empty() 不一定執行。
|
||||
keyHandler.inputMode = newInputMode
|
||||
/// 必須加上下述條件,否則會在每次切換至輸入法本體的視窗(比如偏好設定視窗)時會卡死。
|
||||
/// 這是很多 macOS 副廠輸入法的常見失誤之處。
|
||||
|
|
|
@ -116,9 +116,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
|
|||
let inputting = keyHandler.buildInputtingState
|
||||
|
||||
if mgrPrefs.useSCPCTypingMode {
|
||||
keyHandler.clear()
|
||||
let composingBuffer = inputting.composingBuffer
|
||||
handle(state: InputState.Committing(textToCommit: composingBuffer))
|
||||
handle(state: InputState.Committing(textToCommit: inputting.composingBuffer))
|
||||
// 此時是逐字選字模式,所以「selectedValue.1」是單個字、不用追加處理。
|
||||
if mgrPrefs.associatedPhrasesEnabled,
|
||||
let associatePhrases = keyHandler.buildAssociatePhraseState(
|
||||
|
|
Loading…
Reference in New Issue