From 8b3f2dd994619fd224f54e59b7803d3e7d5896b6 Mon Sep 17 00:00:00 2001 From: Volodymyr Zibarov Date: Mon, 11 Apr 2022 21:22:23 +0300 Subject: [PATCH] TextEdit: Avoid scrolling to cursor during app switch on GNOME GNOME sends empty InputMethod event when switching applications with Alt-Tab. As long as this event is empty, we don't need to scroll to cursor, because we're not adding any input text to it. This also fixes "out of scope" bug QTCREATORBUG-26628 Fixes: QTBUG-100039 Task-number: QTCREATORBUG-26628 Pick-to: 6.2 6.3 Change-Id: I3ccfea50ae52f6f0cbf82c29f07944894050e7dd Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qplaintextedit.cpp | 4 ++++ src/widgets/widgets/qtextedit.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index e30bc64d236..9fb279ece46 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2214,6 +2214,10 @@ void QPlainTextEdit::inputMethodEvent(QInputMethodEvent *e) } #endif d->sendControlEvent(e); + const bool emptyEvent = e->preeditString().isEmpty() && e->commitString().isEmpty() + && e->attributes().isEmpty(); + if (emptyEvent) + return; ensureCursorVisible(); } diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index bff79fc0d1a..5e2a0c053ef 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1808,6 +1808,10 @@ void QTextEdit::inputMethodEvent(QInputMethodEvent *e) setEditFocus(true); #endif d->sendControlEvent(e); + const bool emptyEvent = e->preeditString().isEmpty() && e->commitString().isEmpty() + && e->attributes().isEmpty(); + if (emptyEvent) + return; ensureCursorVisible(); }