InputHandler // Handle inputs for `%quick`.
This commit is contained in:
parent
b0c2bfc54e
commit
ba98ebf0a7
|
@ -99,7 +99,7 @@ extension InputHandler {
|
||||||
: ctlCandidate.highlightNextCandidate())
|
: ctlCandidate.highlightNextCandidate())
|
||||||
_ = updated ? {}() : delegate.callError("9B691919")
|
_ = updated ? {}() : delegate.callError("9B691919")
|
||||||
return true
|
return true
|
||||||
case .kSpace:
|
case .kSpace where state.type != .ofInputting:
|
||||||
let updated: Bool =
|
let updated: Bool =
|
||||||
prefs.specifyShiftSpaceKeyBehavior
|
prefs.specifyShiftSpaceKeyBehavior
|
||||||
? (input.isShiftHold
|
? (input.isShiftHold
|
||||||
|
@ -168,7 +168,8 @@ extension InputHandler {
|
||||||
|
|
||||||
// MARK: 逐字選字模式的處理 (SCPC Mode Processing)
|
// MARK: 逐字選字模式的處理 (SCPC Mode Processing)
|
||||||
|
|
||||||
if prefs.useSCPCTypingMode {
|
// 這裡得排除掉 .ofInputting 模式,否則會在有 `%quick` 結果的情況下無法正常鍵入一個完整的漢字讀音/字根。
|
||||||
|
if prefs.useSCPCTypingMode, state.type != .ofInputting {
|
||||||
/// 檢查:
|
/// 檢查:
|
||||||
/// - 是否是針對當前注音排列/拼音輸入種類專門提供的標點符號。
|
/// - 是否是針對當前注音排列/拼音輸入種類專門提供的標點符號。
|
||||||
/// - 是否是需要摁修飾鍵才可以輸入的那種標點符號。
|
/// - 是否是需要摁修飾鍵才可以輸入的那種標點符號。
|
||||||
|
@ -244,6 +245,8 @@ extension InputHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if state.type == .ofInputting { return false } // `%quick`
|
||||||
|
|
||||||
delegate.callError("172A0F81")
|
delegate.callError("172A0F81")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,14 +212,16 @@ extension InputHandler {
|
||||||
/// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。
|
/// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。
|
||||||
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
|
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
|
||||||
guard let delegate = delegate else { return nil }
|
guard let delegate = delegate else { return nil }
|
||||||
|
let state = delegate.state
|
||||||
var wildcardKey: String { currentLM.cassetteWildcardKey } // 花牌鍵。
|
var wildcardKey: String { currentLM.cassetteWildcardKey } // 花牌鍵。
|
||||||
let inputText = input.text
|
let inputText = input.text
|
||||||
let isWildcardKeyInput: Bool = (inputText == wildcardKey && !wildcardKey.isEmpty)
|
let isWildcardKeyInput: Bool = (inputText == wildcardKey && !wildcardKey.isEmpty)
|
||||||
|
let calligrapherBackup = calligrapher
|
||||||
|
|
||||||
let skipStrokeHandling =
|
let skipStrokeHandling =
|
||||||
input.isReservedKey || input.isNumericPadKey || input.isNonLaptopFunctionKey
|
input.isReservedKey || input.isNumericPadKey || input.isNonLaptopFunctionKey
|
||||||
|| input.isControlHold || input.isOptionHold || input.isCommandHold // || input.isShiftHold
|
|| input.isControlHold || input.isOptionHold || input.isCommandHold // || input.isShiftHold
|
||||||
let confirmCombination = input.isSpace || input.isEnter
|
var confirmCombination = input.isSpace
|
||||||
|
|
||||||
var isLongestPossibleKeyFormed: Bool {
|
var isLongestPossibleKeyFormed: Bool {
|
||||||
guard !isWildcardKeyInput, prefs.autoCompositeWithLongestPossibleCassetteKey else { return false }
|
guard !isWildcardKeyInput, prefs.autoCompositeWithLongestPossibleCassetteKey else { return false }
|
||||||
|
@ -251,11 +253,22 @@ extension InputHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isStrokesFull {
|
if !isStrokesFull {
|
||||||
delegate.switchState(generateStateOfInputting())
|
var result = generateStateOfInputting()
|
||||||
|
// 針對 IMK 選字窗停用 `%quick` 特性,因為按鍵邏輯實在難以實作。
|
||||||
|
if !prefs.useIMKCandidateWindow, !calligrapher.isEmpty,
|
||||||
|
let fetched = currentLM.cassetteQuickSetsFor(key: calligrapher)
|
||||||
|
{
|
||||||
|
result.candidates = fetched.map { (keyArray: [""], value: $0.description) }
|
||||||
|
}
|
||||||
|
delegate.switchState(result)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !(state.type == .ofInputting && state.isCandidateContainer) {
|
||||||
|
confirmCombination = confirmCombination || input.isEnter
|
||||||
|
}
|
||||||
|
|
||||||
var combineStrokes =
|
var combineStrokes =
|
||||||
(isStrokesFull && prefs.autoCompositeWithLongestPossibleCassetteKey)
|
(isStrokesFull && prefs.autoCompositeWithLongestPossibleCassetteKey)
|
||||||
|| (isWildcardKeyInput && !calligrapher.isEmpty)
|
|| (isWildcardKeyInput && !calligrapher.isEmpty)
|
||||||
|
@ -273,8 +286,14 @@ extension InputHandler {
|
||||||
}
|
}
|
||||||
// 向語言模型詢問是否有對應的記錄。
|
// 向語言模型詢問是否有對應的記錄。
|
||||||
if !currentLM.hasUnigramsFor(keyArray: [calligrapher]) {
|
if !currentLM.hasUnigramsFor(keyArray: [calligrapher]) {
|
||||||
delegate.callError("B49C0979_Cassette:語彙庫內無「\(calligrapher)」的匹配記錄。")
|
// 此時立即處理 `%quick` 選字行為。
|
||||||
|
let quickCandidates: Bool = state.type == .ofInputting && state.isCandidateContainer
|
||||||
|
if quickCandidates, handleCandidate(input: input) {
|
||||||
|
if !calligrapher.isEmpty { calligrapher = calligrapherBackup }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate.callError("B49C0979_Cassette:語彙庫內無「\(calligrapher)」的匹配記錄。")
|
||||||
calligrapher.removeAll()
|
calligrapher.removeAll()
|
||||||
// 根據「組字器是否為空」來判定回呼哪一種狀態。
|
// 根據「組字器是否為空」來判定回呼哪一種狀態。
|
||||||
switch compositor.isEmpty {
|
switch compositor.isEmpty {
|
||||||
|
|
|
@ -146,6 +146,10 @@ extension InputHandler {
|
||||||
return handleHaninKeyboardSymbolModeToggle()
|
return handleHaninKeyboardSymbolModeToggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 處理 `%quick` 選字行為。
|
||||||
|
let quickCandidates: Bool = state.type == .ofInputting && state.isCandidateContainer
|
||||||
|
guard !(quickCandidates && handleCandidate(input: input)) else { return true }
|
||||||
|
|
||||||
// 注音按鍵輸入與漢音鍵盤符號輸入處理。
|
// 注音按鍵輸入與漢音鍵盤符號輸入處理。
|
||||||
if isHaninKeyboardSymbolMode, [[], .shift].contains(input.modifierFlags) {
|
if isHaninKeyboardSymbolMode, [[], .shift].contains(input.modifierFlags) {
|
||||||
return handleHaninKeyboardSymbolModeInput(input: input)
|
return handleHaninKeyboardSymbolModeInput(input: input)
|
||||||
|
|
Loading…
Reference in New Issue