KeyHandler // +previousParsableReading().

This commit is contained in:
ShikiSuen 2022-08-23 11:05:32 +08:00
parent 511ab86c55
commit 030b28ccdb
1 changed files with 17 additions and 0 deletions

View File

@ -364,6 +364,23 @@ public class KeyHandler {
composer.phonabetCombinationCorrectionEnabled = mgrPrefs.autoCorrectReadingCombination composer.phonabetCombinationCorrectionEnabled = mgrPrefs.autoCorrectReadingCombination
} }
///
/// 調調
var previousParsableReading: (String, String, Bool)? {
if compositor.cursor == 0 { return nil }
let cursorPrevious = max(compositor.cursor - 1, 0)
let rawData = compositor.keys[cursorPrevious]
let components = rawData.charComponents
var hasIntonation = false
for neta in components {
if !Tekkon.allowedPhonabets.contains(neta) || neta == " " { return nil }
if Tekkon.allowedIntonations.contains(neta) { hasIntonation = true }
}
if hasIntonation, components.count == 1 { return nil } // 調
let rawDataSansIntonation = hasIntonation ? components.dropLast(1).joined() : rawData
return (rawData, rawDataSansIntonation, hasIntonation)
}
// MARK: - Extracted methods and functions (Megrez). // MARK: - Extracted methods and functions (Megrez).
/// ///