InputHandler // Accepting leading intonations.

This commit is contained in:
ShikiSuen 2023-05-05 01:38:25 +08:00
parent c11cf4200c
commit 3f427ae94f
2 changed files with 34 additions and 21 deletions

View File

@ -471,7 +471,7 @@ public class InputHandler: InputHandlerProtocol {
composer.phonabetCombinationCorrectionEnabled = prefs.autoCorrectReadingCombination composer.phonabetCombinationCorrectionEnabled = prefs.autoCorrectReadingCombination
} }
public var isComposerUsingPinyin: Bool { composer.parser.rawValue >= 100 } public var isComposerUsingPinyin: Bool { composer.isPinyinMode }
public func clearComposerAndCalligrapher() { public func clearComposerAndCalligrapher() {
calligrapher.removeAll() calligrapher.removeAll()

View File

@ -30,9 +30,9 @@ extension InputHandler {
/// - Returns: IMK /// - Returns: IMK
private func handlePhonabetComposition(input: InputSignalProtocol) -> Bool? { private func handlePhonabetComposition(input: InputSignalProtocol) -> Bool? {
guard let delegate = delegate else { return nil } guard let delegate = delegate else { return nil }
let existedIntonation = composer.intonation
// 調 // 調 keyConsumedByReading
// keyConsumedByReading
// Space // Space
// 調 // 調
// 調調 // 調調
@ -93,8 +93,8 @@ extension InputHandler {
{ {
return handleEnter(input: input, readingOnly: true) return handleEnter(input: input, readingOnly: true)
} }
// //
guard let readingKey = composer.keyForQuery else { break ifComposeReading } guard let readingKey = composer.keyForQuery(pronouncable: true) else { break ifComposeReading }
// //
if !currentLM.hasUnigramsFor(keyArray: [readingKey]) { if !currentLM.hasUnigramsFor(keyArray: [readingKey]) {
delegate.callError("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。") delegate.callError("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。")
@ -166,7 +166,19 @@ extension InputHandler {
/// 調 /// 調
/// 調 /// 調
if keyConsumedByReading { if keyConsumedByReading {
if composer.abortConsumption { // strict false
if composer.keyForQuery(pronouncable: false) == nil {
// 調
if !composer.isPinyinMode, input.isSpace,
compositor.insertKey(existedIntonation.value)
{
walk()
var theInputting = generateStateOfInputting()
theInputting.textToCommit = commitOverflownComposition
composer.clear()
delegate.switchState(theInputting)
return true
}
composer.clear() composer.clear()
return nil return nil
} }
@ -372,27 +384,28 @@ extension InputHandler {
// //
private extension Tekkon.Composer { extension Tekkon.Composer {
///
var isPinyinMode: Bool { parser.rawValue >= 100 } var isPinyinMode: Bool { parser.rawValue >= 100 }
//
// 使 ///
// /// 使
var keyForQuery: String? { /// - Remark:
/// - Parameter pronouncable:
/// - Returns: nil
func keyForQuery(pronouncable: Bool) -> String? {
let readingKey = getComposition() let readingKey = getComposition()
var validKeyGeneratable = false var validKeyGeneratable = false
switch isPinyinMode { switch isPinyinMode {
case false: case false:
// 調 switch pronouncable {
case false:
validKeyGeneratable = !readingKey.isEmpty validKeyGeneratable = !readingKey.isEmpty
// 調 case true:
// validKeyGeneratable = isPronouncable
// validKeyGeneratable = readingKey.isEmpty ? false : !romajiBuffer.isEmpty }
case true: validKeyGeneratable = !romajiBuffer.isEmpty case true: validKeyGeneratable = isPronouncable
} }
return validKeyGeneratable ? readingKey : nil return validKeyGeneratable ? readingKey : nil
} }
var abortConsumption: Bool {
isPinyinMode ? romajiBuffer.isEmpty : getComposition().isEmpty
}
} }