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
}
public var isComposerUsingPinyin: Bool { composer.parser.rawValue >= 100 }
public var isComposerUsingPinyin: Bool { composer.isPinyinMode }
public func clearComposerAndCalligrapher() {
calligrapher.removeAll()

View File

@ -30,9 +30,9 @@ extension InputHandler {
/// - Returns: IMK
private func handlePhonabetComposition(input: InputSignalProtocol) -> Bool? {
guard let delegate = delegate else { return nil }
let existedIntonation = composer.intonation
// 調
// keyConsumedByReading
// 調 keyConsumedByReading
// Space
// 調
// 調調
@ -93,8 +93,8 @@ extension InputHandler {
{
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]) {
delegate.callError("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。")
@ -166,7 +166,19 @@ extension InputHandler {
/// 調
/// 調
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()
return nil
}
@ -372,27 +384,28 @@ extension InputHandler {
//
private extension Tekkon.Composer {
extension Tekkon.Composer {
///
var isPinyinMode: Bool { parser.rawValue >= 100 }
//
// 使
//
var keyForQuery: String? {
///
/// 使
/// - Remark:
/// - Parameter pronouncable:
/// - Returns: nil
func keyForQuery(pronouncable: Bool) -> String? {
let readingKey = getComposition()
var validKeyGeneratable = false
switch isPinyinMode {
case false:
// 調
switch pronouncable {
case false:
validKeyGeneratable = !readingKey.isEmpty
// 調
//
// validKeyGeneratable = readingKey.isEmpty ? false : !romajiBuffer.isEmpty
case true: validKeyGeneratable = !romajiBuffer.isEmpty
case true:
validKeyGeneratable = isPronouncable
}
case true: validKeyGeneratable = isPronouncable
}
return validKeyGeneratable ? readingKey : nil
}
var abortConsumption: Bool {
isPinyinMode ? romajiBuffer.isEmpty : getComposition().isEmpty
}
}