SessionCtl // Optimize commit().

This commit is contained in:
ShikiSuen 2023-02-09 16:42:32 +08:00
parent 99275a4682
commit ba164520fc
1 changed files with 2 additions and 4 deletions

View File

@ -121,18 +121,16 @@ public extension SessionCtl {
/// IMK commitComposition /// IMK commitComposition
private func commit(text: String) { private func commit(text: String) {
let text = text.trimmingCharacters(in: .newlines) let text = text.trimmingCharacters(in: .newlines)
guard let client = client(), !text.isEmpty else { return }
let buffer = ChineseConverter.kanjiConversionIfRequired(text) let buffer = ChineseConverter.kanjiConversionIfRequired(text)
if buffer.isEmpty {
return
}
if isServingIMEItself { if isServingIMEItself {
DispatchQueue.main.async { DispatchQueue.main.async {
guard let client = self.client() else { return }
client.insertText( client.insertText(
buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
} }
} else { } else {
guard let client = client() else { return }
client.insertText( client.insertText(
buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )