InputHandler // Handle inputs for `%quick`.

This commit is contained in:
ShikiSuen 2023-06-14 16:24:36 +08:00
parent b0c2bfc54e
commit ba98ebf0a7
3 changed files with 31 additions and 5 deletions

View File

@ -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
} }

View File

@ -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 {

View File

@ -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)