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.
This commit is contained in:
thislooksfun 2021-10-28 20:41:56 -05:00 committed by Andreas Kling
commit 7a2c8452f1
Notes: sideshowbarker 2024-07-18 01:34:02 +09:00

View file

@ -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;
}