1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibGUI: Hide autocomplete on any event other than typing

Moving the cursor to a different location, by any means, should
dismiss the autocomplete popup. This is the behavior of virtually
every editor/IDE out there, and it is really annoying (and
confusing) when our autocomplete doesn't behave like that.
This commit is contained in:
thislooksfun 2021-10-27 23:39:55 -05:00 committed by Andreas Kling
parent 0627ed9900
commit 86ea41970d
2 changed files with 18 additions and 7 deletions

View file

@ -738,7 +738,6 @@ void TextEditor::select_all()
void TextEditor::keydown_event(KeyEvent& event)
{
TemporaryChange change { m_should_keep_autocomplete_box, true };
if (m_autocomplete_box && m_autocomplete_box->is_visible() && (event.key() == KeyCode::Key_Return || event.key() == KeyCode::Key_Tab)) {
m_autocomplete_box->apply_suggestion();
m_autocomplete_box->close();
@ -882,6 +881,7 @@ void TextEditor::keydown_event(KeyEvent& event)
}
if (!event.ctrl() && !event.alt() && event.code_point() != 0) {
TemporaryChange change { m_should_keep_autocomplete_box, true };
add_code_point(event.code_point());
return;
}
@ -1469,6 +1469,15 @@ void TextEditor::try_show_autocomplete(UserRequestedAutocomplete user_requested_
}
}
void TextEditor::hide_autocomplete_if_needed()
{
if (m_autocomplete_box && !m_should_keep_autocomplete_box) {
m_autocomplete_box->close();
if (m_autocomplete_timer)
m_autocomplete_timer->stop();
}
}
void TextEditor::enter_event(Core::Event&)
{
m_automatic_selection_scroll_timer->stop();
@ -1484,11 +1493,7 @@ void TextEditor::did_change(AllowCallback allow_callback)
{
update_content_size();
recompute_all_visual_lines();
if (m_autocomplete_box && !m_should_keep_autocomplete_box) {
m_autocomplete_box->close();
if (m_autocomplete_timer)
m_autocomplete_timer->stop();
}
hide_autocomplete_if_needed();
m_needs_rehighlight = true;
if (!m_has_pending_change_notification) {
m_has_pending_change_notification = true;
@ -1827,6 +1832,11 @@ void TextEditor::document_did_set_cursor(TextPosition const& position)
set_cursor(position);
}
void TextEditor::cursor_did_change()
{
hide_autocomplete_if_needed();
}
void TextEditor::clipboard_content_did_change(String const& mime_type)
{
m_paste_action->set_enabled(is_editable() && mime_type.starts_with("text/") && !Clipboard::the().data().is_empty());