From 119f0d02bea701d1494354178d0392136315724c Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Wed, 22 Dec 2021 15:00:09 -0800 Subject: [PATCH] Do no send empty preedit string to text-input-v3. zwp_input_method_v1 has some different semantics comparing to text-input-v3. There is no way to indicate that "clear preedit" with zwp_input_method_v1. In some client (Namely, Gtk), receiving an empty preedit string will also trigger replace selection action. For example, focus into address bar in firefox will automatically select the URL in the address bar, and a following empty preedit string will clear the selection which is not desirable. To avoid such behavior, simply send an empty "done()" to clear text input v3 preedit if preedit is empty. --- src/inputmethod.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/inputmethod.cpp b/src/inputmethod.cpp index b30b85df29..e68fd8bf68 100644 --- a/src/inputmethod.cpp +++ b/src/inputmethod.cpp @@ -475,7 +475,9 @@ void InputMethod::setPreeditString(uint32_t serial, const QString &text, const Q auto t3 = waylandServer()->seat()->textInputV3(); if (t3 && t3->isEnabled()) { preedit.text = text; - t3->sendPreEditString(preedit.text, preedit.begin, preedit.end); + if (!preedit.text.isEmpty()) { + t3->sendPreEditString(preedit.text, preedit.begin, preedit.end); + } t3->done(); } }