SessionCtl // Add one more replacement attempt to the final commit.

This commit is contained in:
ShikiSuen 2023-08-27 17:15:52 +08:00
parent 3a8060bf88
commit 16750e4bde
2 changed files with 16 additions and 2 deletions

View File

@ -233,6 +233,11 @@ public extension vChewingLM {
lmAssociates.valuesFor(pair: pair) lmAssociates.valuesFor(pair: pair)
} }
public func queryReplacementValue(key: String) -> String? {
let result = lmReplacements.valuesFor(key: key)
return result.isEmpty ? nil : result
}
/// ///
/// - Parameters: /// - Parameters:
/// - key: /// - key:

View File

@ -129,8 +129,17 @@ public extension SessionCtl {
/// ///
/// IMK commitComposition /// IMK commitComposition
private func commit(text: String) { private func commit(text: String) {
let text = text.trimmingCharacters(in: .newlines) let phE = PrefMgr.shared.phraseReplacementEnabled && text.count > 1
let buffer = ChineseConverter.kanjiConversionIfRequired(text) var text = text.trimmingCharacters(in: .newlines)
var replaced = false
if phE, let queried = inputHandler?.currentLM.queryReplacementValue(key: text) {
replaced = true
text = queried
}
var buffer = ChineseConverter.kanjiConversionIfRequired(text)
if phE, !replaced, let queried = inputHandler?.currentLM.queryReplacementValue(key: buffer) {
buffer = ChineseConverter.kanjiConversionIfRequired(queried)
}
if isServingIMEItself { if isServingIMEItself {
DispatchQueue.main.async { DispatchQueue.main.async {
guard let client = self.client() else { return } guard let client = self.client() else { return }