From 7db49a22b22bda247dda1cc2c3cddcc36e3372c6 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Fri, 5 Jul 2024 19:06:41 -0400 Subject: [PATCH] use zero width space as dummy preedit to avoid text shift --- macosfrontend/macosfrontend.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/macosfrontend/macosfrontend.swift b/macosfrontend/macosfrontend.swift index 4aa8280..03963f2 100644 --- a/macosfrontend/macosfrontend.swift +++ b/macosfrontend/macosfrontend.swift @@ -4,6 +4,8 @@ import InputMethodKit private var u16pos = 0 private var currentPreedit = "" +private let zeroWidthSpace = "\u{200B}" + private func commitString(_ client: IMKTextInput, _ string: String) { client.insertText(string, replacementRange: NSRange(location: NSNotFound, length: NSNotFound)) } @@ -42,7 +44,7 @@ public func commitAndSetPreeditSync( // But when there is selected text, we don't want the dummy preedit to clear all of // them. An example is using Shift+click to select but IM switch happens. if preedit.isEmpty && dummyPreedit && client.selectedRange().length == 0 { - setPreedit(client, " ", 0) + setPreedit(client, zeroWidthSpace, 0) } else { setPreedit(client, preedit, cursorPos) }