InputHandler // Implement (BOOL)handleCandidateInput:ignoringModifiers:.

This commit is contained in:
ShikiSuen 2024-01-18 13:18:19 +08:00
parent 71dc1afc48
commit 5e1208bc5e
2 changed files with 12 additions and 12 deletions

View File

@ -18,14 +18,17 @@ import Shared
extension InputHandler {
///
/// - Parameter input:
/// - Parameters:
/// - input:
/// - ignoringModifiers:
/// - Returns: IMK
func handleCandidate(input: InputSignalProtocol) -> Bool {
func handleCandidate(input: InputSignalProtocol, ignoringModifiers: Bool = false) -> Bool {
guard let delegate = delegate else { return false }
guard var ctlCandidate = delegate.candidateController() else { return false }
let state = delegate.state
guard state.isCandidateContainer else { return false } // isEmpty
guard ctlCandidate.visible else { return false }
let inputText = ignoringModifiers ? (input.inputTextIgnoringModifiers ?? input.text) : input.text
// MARK: 使
@ -184,7 +187,7 @@ extension InputHandler {
let cassetteShift = currentLM.areCassetteCandidateKeysShiftHeld
shaltShiftHold = shaltShiftHold || cassetteShift
}
let matched: String = shaltShiftHold ? input.inputTextIgnoringModifiers ?? "" : input.text
let matched: String = shaltShiftHold ? input.inputTextIgnoringModifiers ?? "" : inputText
checkSelectionKey: for keyPair in delegate.selectionKeys.enumerated() {
guard matched.lowercased() == keyPair.element.lowercased() else { continue }
index = Int(keyPair.offset)
@ -210,27 +213,27 @@ extension InputHandler {
let punctuationNamePrefix: String = generatePunctuationNamePrefix(withKeyCondition: input)
let parser = currentKeyboardParser
let arrCustomPunctuations: [String] = [
punctuationNamePrefix, parser, input.text,
punctuationNamePrefix, parser, inputText,
]
let customPunctuation: String = arrCustomPunctuations.joined()
///
let arrPunctuations: [String] = [
punctuationNamePrefix, input.text,
punctuationNamePrefix, inputText,
]
let punctuation: String = arrPunctuations.joined()
let isInputValid: Bool =
prefs.cassetteEnabled
? currentLM.isThisCassetteKeyAllowed(key: input.text) : composer.inputValidityCheck(key: input.charCode)
? currentLM.isThisCassetteKeyAllowed(key: inputText) : composer.inputValidityCheck(key: input.charCode)
var shouldAutoSelectCandidate: Bool =
isInputValid || currentLM.hasUnigramsFor(keyArray: [customPunctuation])
|| currentLM.hasUnigramsFor(keyArray: [punctuation])
if !shouldAutoSelectCandidate, input.isUpperCaseASCIILetterKey {
let letter = "_letter_\(input.text)"
let letter = "_letter_\(inputText)"
if currentLM.hasUnigramsFor(keyArray: [letter]) { shouldAutoSelectCandidate = true }
}

View File

@ -30,12 +30,9 @@ extension InputHandler {
// `%symboldef`
if handleCassetteSymbolTable(input: input) {
return true
} else if hasQuickCandidates, input.text != currentLM.cassetteWildcardKey,
let itim = input.inputTextIgnoringModifiers,
let newEv = (input as? NSEvent)?.reinitiate(characters: itim)
{
} else if hasQuickCandidates, input.text != currentLM.cassetteWildcardKey {
// `%quick` `%symboldef`
guard !(handleQuickCandidate && handleCandidate(input: newEv)) else { return true }
guard !(handleQuickCandidate && handleCandidate(input: input, ignoringModifiers: true)) else { return true }
} else {
// `%quick`
guard !(hasQuickCandidates && handleQuickCandidate && handleCandidate(input: input)) else { return true }