InputHandler // Simplify handleComposition().

This commit is contained in:
ShikiSuen 2023-05-04 18:31:47 +08:00
parent a81fe379c2
commit dd13a1218e
1 changed files with 41 additions and 12 deletions

View File

@ -31,6 +31,11 @@ extension InputHandler {
private func handlePhonabetComposition(input: InputSignalProtocol) -> Bool? {
guard let delegate = delegate else { return nil }
// 調
// keyConsumedByReading
// Space
// 調
// 調調
var keyConsumedByReading = false
let skipPhoneticHandling =
input.isReservedKey || input.isNumericPadKey || input.isNonLaptopFunctionKey
@ -78,25 +83,18 @@ extension InputHandler {
}
}
let readingKey = composer.getComposition() //
//
var composeReading = composer.hasIntonation() && composer.inputValidityCheck(key: input.charCode) //
// Enter Space composer
// |=
// 使 composer.value.isEmpty composer 調
composeReading = composeReading || (!composer.isEmpty && confirmCombination)
// readingKey
var isReadingKeyNotEmpty = !readingKey.isEmpty
if isComposerUsingPinyin {
isReadingKeyNotEmpty = isReadingKeyNotEmpty || !composer.romajiBuffer.isEmpty
}
composeReading = composeReading && isReadingKeyNotEmpty
if composeReading {
ifComposeReading: if composeReading {
if input.isControlHold, input.isCommandHold, input.isEnter,
!input.isOptionHold, !input.isShiftHold, compositor.isEmpty
{
return handleEnter(input: input, readingOnly: true)
}
//
guard let readingKey = composer.keyForQuery else { break ifComposeReading }
//
if !currentLM.hasUnigramsFor(keyArray: [readingKey]) {
delegate.callError("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。")
@ -168,7 +166,7 @@ extension InputHandler {
/// 調
/// 調
if keyConsumedByReading {
if readingKey.isEmpty {
if composer.abortConsumption {
composer.clear()
return nil
}
@ -241,7 +239,9 @@ extension InputHandler {
// Enter Space calligrapher
// |=
combineStrokes = combineStrokes || (!calligrapher.isEmpty && confirmCombination)
if combineStrokes {
ifCombineStrokes: if combineStrokes {
// calligrapher
guard !calligrapher.isEmpty else { break ifCombineStrokes }
if input.isControlHold, input.isCommandHold, input.isEnter,
!input.isOptionHold, !input.isShiftHold, composer.isEmpty
{
@ -375,3 +375,32 @@ extension InputHandler {
}
}
}
// MARK: - Private Extensions for Tekkon Composer
//
private extension Tekkon.Composer {
var isPinyinMode: Bool { parser.rawValue >= 100 }
//
// 使
//
var keyForQuery: String? {
let readingKey = getComposition()
var validKeyGeneratable = false
switch isPinyinMode {
case false:
// 調
validKeyGeneratable = !readingKey.isEmpty
// 調
//
// validKeyGeneratable = readingKey.isEmpty ? false : !romajiBuffer.isEmpty
case true: validKeyGeneratable = !romajiBuffer.isEmpty
}
return validKeyGeneratable ? readingKey : nil
}
var abortConsumption: Bool {
isPinyinMode ? romajiBuffer.isEmpty : getComposition().isEmpty
}
}