From 84a2e3fdb040fc7d23b413b8ff7a818f2e5c5d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Thu, 20 Feb 2025 08:23:22 +0200 Subject: [PATCH] [IME] Do not redraw and move caret on IME update w/o text/position changes. --- scene/gui/line_edit.cpp | 10 ++++++++-- scene/gui/text_edit.cpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index b4cad350e21..969e2fd3a35 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1377,8 +1377,14 @@ void LineEdit::_notification(int p_what) { case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (editing) { - ime_text = DisplayServer::get_singleton()->ime_get_text(); - ime_selection = DisplayServer::get_singleton()->ime_get_selection(); + const String &new_ime_text = DisplayServer::get_singleton()->ime_get_text(); + const Vector2i &new_ime_selection = DisplayServer::get_singleton()->ime_get_selection(); + if (ime_text == new_ime_text && ime_selection == new_ime_selection) { + break; + } + + ime_text = new_ime_text; + ime_selection = new_ime_selection; if (!ime_text.is_empty()) { selection_delete(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c2c01326378..ad220231500 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1633,9 +1633,15 @@ void TextEdit::_notification(int p_what) { case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { + const String &new_ime_text = DisplayServer::get_singleton()->ime_get_text(); + const Vector2i &new_ime_selection = DisplayServer::get_singleton()->ime_get_selection(); + if (ime_text == new_ime_text && ime_selection == new_ime_selection) { + break; + } + bool had_ime_text = has_ime_text(); - ime_text = DisplayServer::get_singleton()->ime_get_text(); - ime_selection = DisplayServer::get_singleton()->ime_get_selection(); + ime_text = new_ime_text; + ime_selection = new_ime_selection; if (!had_ime_text && has_ime_text()) { _cancel_drag_and_drop_text();