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.
This commit is contained in:
Andreas Kling 2026-06-20 23:51:58 +02:00 committed by Andreas Kling
parent e2d223b305
commit 375da3e66d
4 changed files with 30 additions and 2 deletions

View file

@ -471,8 +471,10 @@ void Autocomplete::show_with_suggestions(Vector<WebView::AutocompleteSuggestion>
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)

View file

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

View file

@ -43,6 +43,7 @@ public:
void set_url(Optional<URL::URL>);
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;
};

View file

@ -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)