From 375da3e66d599f615f18c126786271e2148685fc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 Jun 2026 23:51:58 +0200 Subject: [PATCH] UI/Qt: Show autocomplete when focusing location edit Open the autocomplete popup when the location editor is focused through the browser action, such as Cmd+L. Keep the selected URL text intact by skipping inline completion for that explicit popup request. Position the native popup again after its first show so Qt has realized the tooltip window before the final placement, avoiding the brief macOS Y-coordinate jump. --- UI/Qt/Autocomplete.cpp | 6 +++++- UI/Qt/LocationEdit.cpp | 23 ++++++++++++++++++++++- UI/Qt/LocationEdit.h | 2 ++ UI/Qt/Tab.cpp | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/UI/Qt/Autocomplete.cpp b/UI/Qt/Autocomplete.cpp index f510a67fe0..6229347e3a 100644 --- a/UI/Qt/Autocomplete.cpp +++ b/UI/Qt/Autocomplete.cpp @@ -471,8 +471,10 @@ void Autocomplete::show_with_suggestions(Vector update_chrome_style(); position_popup(); - if (!m_popup->isVisible()) + if (!m_popup->isVisible()) { m_popup->show(); + position_popup(); + } m_popup->raise(); int table_row = m_model->table_row_for_suggestion_index(selected_suggestion_index); @@ -522,6 +524,7 @@ bool Autocomplete::select_next_suggestion() if (!m_popup->isVisible()) { position_popup(); m_popup->show(); + position_popup(); m_popup->raise(); int row = step_to_selectable_row(-1, 1); if (row != -1) @@ -545,6 +548,7 @@ bool Autocomplete::select_previous_suggestion() if (!m_popup->isVisible()) { position_popup(); m_popup->show(); + position_popup(); m_popup->raise(); int row = step_to_selectable_row(0, -1); if (row != -1) diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cpp index c10c1bb667..2e3a321d80 100644 --- a/UI/Qt/LocationEdit.cpp +++ b/UI/Qt/LocationEdit.cpp @@ -253,7 +253,11 @@ LocationEdit::LocationEdit(QWidget* parent) update_location_icon(); m_autocomplete->on_query_complete = [this](auto suggestions, WebView::AutocompleteResultKind result_kind) { - int selected_row = apply_inline_autocomplete(suggestions); + int selected_row = -1; + if (!m_autocomplete_query_without_inline.isNull() && text() == m_autocomplete_query_without_inline) + selected_row = 0; + else + selected_row = apply_inline_autocomplete(suggestions); // Do not update the popup while results are still changing. // Intermediate updates are triggered on every keystroke and would @@ -280,6 +284,10 @@ LocationEdit::LocationEdit(QWidget* parent) connect(m_autocomplete, &Autocomplete::did_close, this, [this] { m_current_inline_autocomplete_suggestion.clear(); + if (!m_autocomplete_query_without_inline.isNull()) { + m_autocomplete_query_without_inline = QString(); + return; + } restore_query(); }); @@ -303,6 +311,8 @@ LocationEdit::LocationEdit(QWidget* parent) if (m_is_applying_inline_autocomplete) return; + m_autocomplete_query_without_inline = QString(); + if (m_url_is_hidden) m_has_user_edited_hidden_url = true; @@ -378,6 +388,16 @@ void LocationEdit::set_url_is_hidden(bool url_is_hidden) clear(); } +void LocationEdit::show_autocomplete() +{ + if (!window() || !window()->isVisible()) + return; + + auto query = text(); + m_autocomplete_query_without_inline = query; + m_autocomplete->query_autocomplete_engine(ak_string_from_qstring(query)); +} + void LocationEdit::changeEvent(QEvent* event) { QLineEdit::changeEvent(event); @@ -1072,6 +1092,7 @@ void LocationEdit::restore_query() void LocationEdit::reset_autocomplete_state() { + m_autocomplete_query_without_inline = QString(); m_current_inline_autocomplete_suggestion.clear(); m_suppressed_inline_autocomplete_query = QString(); m_should_suppress_inline_autocomplete_on_next_change = false; diff --git a/UI/Qt/LocationEdit.h b/UI/Qt/LocationEdit.h index c77e5056a1..70e13dce09 100644 --- a/UI/Qt/LocationEdit.h +++ b/UI/Qt/LocationEdit.h @@ -43,6 +43,7 @@ public: void set_url(Optional); bool url_is_hidden() const { return m_url_is_hidden; } void set_url_is_hidden(bool); + void show_autocomplete(); private: virtual void changeEvent(QEvent* event) override; @@ -97,6 +98,7 @@ private: bool m_is_applying_inline_autocomplete { false }; bool m_should_suppress_inline_autocomplete_on_next_change { false }; + QString m_autocomplete_query_without_inline; QString m_current_inline_autocomplete_suggestion; QString m_suppressed_inline_autocomplete_query; }; diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp index cab4b91c06..dac8dbf3b5 100644 --- a/UI/Qt/Tab.cpp +++ b/UI/Qt/Tab.cpp @@ -600,6 +600,7 @@ void Tab::focus_location_editor() { m_location_edit->setFocus(); m_location_edit->selectAll(); + m_location_edit->show_autocomplete(); } void Tab::set_window(BrowserWindow& window)