Skip to content

Truly independent web browser

LibWebView: Show the typed text in the omnibox popup without waiting

Andreas Kling5234b3685fd2
diff --git a/Libraries/LibWebView/Omnibox.cpp b/Libraries/LibWebView/Omnibox.cpp
index 0fde1e05ead..bc9d2cbb022 100644
--- a/Libraries/LibWebView/Omnibox.cpp
+++ b/Libraries/LibWebView/Omnibox.cpp
@@ -419,6 +419,8 @@ void Omnibox::received_suggestions(AutocompleteQueryID query_id, Vector<Autocomp
// NB: The popup keeps the rows it shows until the final ones arrive, rather than showing each delivery on the way.
if (kind == AutocompleteResultKind::Final)
present_popup();
+ else
+ show_typed_text_in_popup();
}
// When Return goes to the text as typed, because the user rejected a completion or because the top row may not be
@@ -870,11 +872,28 @@ void Omnibox::close_popup()
}
// Has the popup show the suggestions as they are now.
+// The row for the text as typed does not depend on what the text brings up, so the popup shows the one for the current
+// text as soon as there is one, in the place of the one it has. Its other rows wait for the final ones.
+void Omnibox::show_typed_text_in_popup()
+{
+ if (!m_popup.is_visible || m_popup_typed_text == m_query)
+ return;
+ auto current_row = index_of_typed_text_suggestion(m_query, m_suggestions);
+ auto shown_row = index_of_typed_text_suggestion(m_popup_typed_text, m_popup.suggestions);
+ if (!current_row.has_value() || !shown_row.has_value())
+ return;
+ m_popup.suggestions[*shown_row] = m_suggestions[*current_row];
+ m_popup_typed_text = m_query;
+ if (on_popup_change)
+ on_popup_change();
+}
+
void Omnibox::present_popup()
{
m_popup.is_visible = m_popup_visible;
m_popup.suggestions = m_suggestions;
m_popup.selected_suggestion = selected_suggestion();
+ m_popup_typed_text = m_popup_query;
m_popup_shows_current_suggestions = true;
if (on_popup_change)
on_popup_change();
diff --git a/Libraries/LibWebView/Omnibox.h b/Libraries/LibWebView/Omnibox.h
index 7a4e5a558e5..a0ea418162d 100644
--- a/Libraries/LibWebView/Omnibox.h
+++ b/Libraries/LibWebView/Omnibox.h
@@ -205,6 +205,7 @@ private:
void show_popup();
void close_popup();
void present_popup();
+ void show_typed_text_in_popup();
void abandon_popup_session();
void set_selection(Optional<Selection>);
void commit(String text, OmniboxDestinationKind);
@@ -265,6 +266,8 @@ private:
Optional<Selection> m_selection;
Popup m_popup;
+ // The text that the popup's row for the text as typed is for.
+ String m_popup_typed_text;
// Whether the popup shows the suggestions as they are now, so that a row has the same index in both.
bool m_popup_shows_current_suggestions { false };
diff --git a/Tests/LibWebView/TestOmnibox.cpp b/Tests/LibWebView/TestOmnibox.cpp
index 5a434bca725..896f9079bb5 100644
--- a/Tests/LibWebView/TestOmnibox.cpp
+++ b/Tests/LibWebView/TestOmnibox.cpp
@@ -2086,20 +2086,25 @@ TEST_CASE(the_popup_waits_for_the_final_rows)
EXPECT_EQ(harness.shown_popup.selected_suggestion, 0u);
EXPECT_EQ(harness.popup_changes, 1u);
- // It keeps those rows as the text changes and as the local rows for the new text arrive.
+ // It keeps those rows as the text changes and as the local rows for the new text arrive, except for the row for
+ // the text as typed, which follows the text at once.
harness.press_key('h');
+ EXPECT_EQ(harness.popup_changes, 1u);
harness.provider->deliver_intermediate({ history_row("https://www.thee.example/"sv), search_row("th"sv) });
EXPECT_EQ(harness.display_text, "thee.example"sv);
EXPECT_EQ(harness.omnibox.suggestions().size(), 2u);
EXPECT_EQ(harness.shown_popup.suggestions.size(), 3u);
- EXPECT_EQ(harness.shown_popup.suggestions.first().text, "https://www.twin.example/"sv);
- EXPECT_EQ(harness.popup_changes, 1u);
+ EXPECT_EQ(harness.shown_popup.suggestions[0].text, "https://www.twin.example/"sv);
+ EXPECT_EQ(harness.shown_popup.suggestions[1].text, "th"sv);
+ EXPECT_EQ(harness.shown_popup.suggestions[2].text, "tea"sv);
+ EXPECT_EQ(harness.shown_popup.selected_suggestion, 0u);
+ EXPECT_EQ(harness.popup_changes, 2u);
- // It changes once for the key press, to the final rows.
+ // Its other rows change once for the key press, to the final rows.
harness.provider->deliver({ history_row("https://www.thee.example/"sv), search_row("th"sv), search_row("the"sv), search_row("they"sv) });
EXPECT_EQ(harness.shown_popup.suggestions.size(), 4u);
EXPECT_EQ(harness.shown_popup.suggestions.first().text, "https://www.thee.example/"sv);
- EXPECT_EQ(harness.popup_changes, 2u);
+ EXPECT_EQ(harness.popup_changes, 3u);
// Return goes to the completion without waiting for the popup.
harness.press_key('e');
@@ -2120,7 +2125,8 @@ TEST_CASE(stepping_through_the_rows_shows_them_before_the_final_ones)
harness.provider->deliver({ search_row("t"sv), search_row("tea"sv) });
harness.press_key('h');
harness.provider->deliver_intermediate({ search_row("th"sv), history_row("https://www.thee.example/"sv) });
- EXPECT_EQ(harness.shown_popup.suggestions.first().text, "t"sv);
+ EXPECT_EQ(harness.shown_popup.suggestions.first().text, "th"sv);
+ EXPECT_EQ(harness.shown_popup.suggestions.last().text, "tea"sv);
// The arrow keys step through the rows as they are now, so the popup shows them.
EXPECT(harness.omnibox.select_next_suggestion());