From 7a2c8452f167a938a46a219078e8a113c4768db8 Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Thu, 28 Oct 2021 20:41:56 -0500 Subject: [PATCH] LibGUI: Don't re-trigger the autocomplete box when the timer fires Previously there was a situation where the autocomplete box would appear to "jump" to the side. This was due to the following race condition: 1. Start typing, thus triggering the autocomplete timer to start 2. Manually trigger autocomplete before the timer finishes 3. Continue typing 4. The autocomplete timer now fires When the timer fires it causes the autocomplete box to show, which, if it is already shown, has the effect of moving the box to the current cursor position. --- Userland/Libraries/LibGUI/TextEditor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 0d8fb9e17b..ef7c18e038 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -1987,7 +1987,10 @@ void TextEditor::set_should_autocomplete_automatically(bool value) if (value) { VERIFY(m_autocomplete_provider); - m_autocomplete_timer = Core::Timer::create_single_shot(m_automatic_autocomplete_delay_ms, [this] { try_show_autocomplete(UserRequestedAutocomplete::No); }); + m_autocomplete_timer = Core::Timer::create_single_shot(m_automatic_autocomplete_delay_ms, [this] { + if (m_autocomplete_box && !m_autocomplete_box->is_visible()) + try_show_autocomplete(UserRequestedAutocomplete::No); + }); return; }