KeyHandler // Stop generating candidate states with emply container.
This commit is contained in:
parent
1dfebd7b44
commit
b510ee5c1e
|
@ -126,23 +126,25 @@ extension KeyHandler {
|
||||||
|
|
||||||
/// 逐字選字模式的處理。
|
/// 逐字選字模式的處理。
|
||||||
if prefs.useSCPCTypingMode {
|
if prefs.useSCPCTypingMode {
|
||||||
let candidateState: IMEState = buildCandidate(state: inputting)
|
let candidateState: IMEStateProtocol = buildCandidate(state: inputting)
|
||||||
if candidateState.candidates.count == 1, let firstCandidate = candidateState.candidates.first {
|
switch candidateState.candidates.count {
|
||||||
let reading: String = firstCandidate.0
|
case 2...: stateCallback(candidateState)
|
||||||
let text: String = firstCandidate.1
|
case 1:
|
||||||
stateCallback(IMEState.ofCommitting(textToCommit: text))
|
let firstCandidate = candidateState.candidates.first! // 一定會有,所以強制拆包也無妨。
|
||||||
|
let reading: String = firstCandidate.0
|
||||||
|
let text: String = firstCandidate.1
|
||||||
|
stateCallback(IMEState.ofCommitting(textToCommit: text))
|
||||||
|
|
||||||
if !prefs.associatedPhrasesEnabled {
|
if !prefs.associatedPhrasesEnabled {
|
||||||
stateCallback(IMEState.ofEmpty())
|
stateCallback(IMEState.ofEmpty())
|
||||||
} else {
|
} else {
|
||||||
let associatedPhrases =
|
let associatedPhrases =
|
||||||
buildAssociatePhraseState(
|
buildAssociatePhraseState(
|
||||||
withPair: .init(key: reading, value: text)
|
withPair: .init(key: reading, value: text)
|
||||||
)
|
)
|
||||||
stateCallback(associatedPhrases.candidates.isEmpty ? IMEState.ofEmpty() : associatedPhrases)
|
stateCallback(associatedPhrases.candidates.isEmpty ? IMEState.ofEmpty() : associatedPhrases)
|
||||||
}
|
}
|
||||||
} else {
|
default: break
|
||||||
stateCallback(candidateState)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 將「這個按鍵訊號已經被輸入法攔截處理了」的結果藉由 SessionCtl 回報給 IMK。
|
// 將「這個按鍵訊號已經被輸入法攔截處理了」的結果藉由 SessionCtl 回報給 IMK。
|
||||||
|
|
|
@ -176,7 +176,12 @@ extension KeyHandler {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stateCallback(buildCandidate(state: state))
|
let candidateState: IMEStateProtocol = buildCandidate(state: state)
|
||||||
|
if candidateState.candidates.isEmpty {
|
||||||
|
errorCallback("3572F238")
|
||||||
|
} else {
|
||||||
|
stateCallback(candidateState)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +294,12 @@ extension KeyHandler {
|
||||||
var inputting = buildInputtingState
|
var inputting = buildInputtingState
|
||||||
inputting.textToCommit = textToCommit
|
inputting.textToCommit = textToCommit
|
||||||
stateCallback(inputting)
|
stateCallback(inputting)
|
||||||
stateCallback(buildCandidate(state: inputting))
|
let candidateState = buildCandidate(state: inputting)
|
||||||
|
if candidateState.candidates.isEmpty {
|
||||||
|
errorCallback("B5127D8A")
|
||||||
|
} else {
|
||||||
|
stateCallback(candidateState)
|
||||||
|
}
|
||||||
} else { // 不要在注音沒敲完整的情況下叫出統合符號選單。
|
} else { // 不要在注音沒敲完整的情況下叫出統合符號選單。
|
||||||
errorCallback("17446655")
|
errorCallback("17446655")
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ extension KeyHandler {
|
||||||
// MARK: - 構築狀態(State Building)
|
// MARK: - 構築狀態(State Building)
|
||||||
|
|
||||||
/// 生成「正在輸入」狀態。相關的內容會被拿給狀態機械用來處理在電腦螢幕上顯示的內容。
|
/// 生成「正在輸入」狀態。相關的內容會被拿給狀態機械用來處理在電腦螢幕上顯示的內容。
|
||||||
public var buildInputtingState: IMEState {
|
public var buildInputtingState: IMEStateProtocol {
|
||||||
/// 「更新內文組字區 (Update the composing buffer)」是指要求客體軟體將組字緩衝區的內容
|
/// 「更新內文組字區 (Update the composing buffer)」是指要求客體軟體將組字緩衝區的內容
|
||||||
/// 換成由此處重新生成的組字字串(NSAttributeString,否則會不顯示)。
|
/// 換成由此處重新生成的組字字串(NSAttributeString,否則會不顯示)。
|
||||||
var displayTextSegments: [String] = compositor.walkedNodes.values
|
var displayTextSegments: [String] = compositor.walkedNodes.values
|
||||||
|
@ -85,11 +85,10 @@ extension KeyHandler {
|
||||||
/// 拿著給定的候選字詞陣列資料內容,切換至選字狀態。
|
/// 拿著給定的候選字詞陣列資料內容,切換至選字狀態。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - currentState: 當前狀態。
|
/// - currentState: 當前狀態。
|
||||||
/// - isTypingVertical: 是否縱排輸入?
|
|
||||||
/// - Returns: 回呼一個新的選詞狀態,來就給定的候選字詞陣列資料內容顯示選字窗。
|
/// - Returns: 回呼一個新的選詞狀態,來就給定的候選字詞陣列資料內容顯示選字窗。
|
||||||
func buildCandidate(
|
func buildCandidate(
|
||||||
state currentState: IMEStateProtocol
|
state currentState: IMEStateProtocol
|
||||||
) -> IMEState {
|
) -> IMEStateProtocol {
|
||||||
IMEState.ofCandidates(
|
IMEState.ofCandidates(
|
||||||
candidates: getCandidatesArray(fixOrder: prefs.useFixecCandidateOrderOnSelection),
|
candidates: getCandidatesArray(fixOrder: prefs.useFixecCandidateOrderOnSelection),
|
||||||
displayTextSegments: compositor.walkedNodes.values,
|
displayTextSegments: compositor.walkedNodes.values,
|
||||||
|
@ -113,7 +112,7 @@ extension KeyHandler {
|
||||||
/// - Returns: 回呼一個新的聯想詞狀態,來就給定的聯想詞陣列資料內容顯示選字窗。
|
/// - Returns: 回呼一個新的聯想詞狀態,來就給定的聯想詞陣列資料內容顯示選字窗。
|
||||||
func buildAssociatePhraseState(
|
func buildAssociatePhraseState(
|
||||||
withPair pair: Megrez.Compositor.KeyValuePaired
|
withPair pair: Megrez.Compositor.KeyValuePaired
|
||||||
) -> IMEState {
|
) -> IMEStateProtocol {
|
||||||
IMEState.ofAssociates(
|
IMEState.ofAssociates(
|
||||||
candidates: buildAssociatePhraseArray(withPair: pair))
|
candidates: buildAssociatePhraseArray(withPair: pair))
|
||||||
}
|
}
|
||||||
|
@ -232,7 +231,6 @@ extension KeyHandler {
|
||||||
/// 標點輸入的處理。
|
/// 標點輸入的處理。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - customPunctuation: 自訂標點索引鍵頭。
|
/// - customPunctuation: 自訂標點索引鍵頭。
|
||||||
/// - isTypingVertical: 是否縱排輸入?
|
|
||||||
/// - stateCallback: 狀態回呼。
|
/// - stateCallback: 狀態回呼。
|
||||||
/// - errorCallback: 錯誤回呼。
|
/// - errorCallback: 錯誤回呼。
|
||||||
/// - Returns: 將按鍵行為「是否有處理掉」藉由 SessionCtl 回報給 IMK。
|
/// - Returns: 將按鍵行為「是否有處理掉」藉由 SessionCtl 回報給 IMK。
|
||||||
|
@ -265,16 +263,17 @@ extension KeyHandler {
|
||||||
guard prefs.useSCPCTypingMode, composer.isEmpty else { return true }
|
guard prefs.useSCPCTypingMode, composer.isEmpty else { return true }
|
||||||
|
|
||||||
let candidateState = buildCandidate(state: inputting)
|
let candidateState = buildCandidate(state: inputting)
|
||||||
if candidateState.candidates.count == 1 {
|
switch candidateState.candidates.count {
|
||||||
clear() // 這句不要砍,因為下文可能會回呼 candidateState。
|
case 2...: stateCallback(candidateState)
|
||||||
if let candidateToCommit: (String, String) = candidateState.candidates.first, !candidateToCommit.1.isEmpty {
|
case 1:
|
||||||
stateCallback(IMEState.ofCommitting(textToCommit: candidateToCommit.1))
|
clear() // 這句不要砍,因為下文可能會回呼 candidateState。
|
||||||
stateCallback(IMEState.ofEmpty())
|
if let candidateToCommit: (String, String) = candidateState.candidates.first, !candidateToCommit.1.isEmpty {
|
||||||
} else {
|
stateCallback(IMEState.ofCommitting(textToCommit: candidateToCommit.1))
|
||||||
stateCallback(candidateState)
|
stateCallback(IMEState.ofEmpty())
|
||||||
}
|
} else {
|
||||||
} else {
|
stateCallback(candidateState)
|
||||||
stateCallback(candidateState)
|
}
|
||||||
|
default: errorCallback("8DA4096E")
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue