Skip to content

Truly independent web browser

LibWebView: Let the omnibox say where Return goes

Andreas Kling167434afc13a
diff --git a/Libraries/LibWebView/Omnibox.cpp b/Libraries/LibWebView/Omnibox.cpp
index 87aee95491f..c01ef9e1f3b 100644
--- a/Libraries/LibWebView/Omnibox.cpp
+++ b/Libraries/LibWebView/Omnibox.cpp
@@ -474,40 +474,46 @@ void Omnibox::return_pressed()
return;
}
- if (selection_is_explicit()) {
+ if (suggestion_index_for_return().has_value()) {
activate_selected_suggestion();
return;
}
- // The user edited or deleted a completion, so submit the text as typed instead of the popup's
- // automatically selected row. Rows the user chose deliberately still win.
- if (m_user_rejected_completion && !selection_is_explicit()) {
- Optional<String> selected_text;
- if (m_popup_query_id == m_active_query_id && m_selection.has_value())
- selected_text = m_suggestions[m_selection->index].text;
- if (!completion_is_suppressed() && selected_text.has_value() && *selected_text != m_query) {
- activate_selected_suggestion();
- return;
- }
+ auto query = m_query;
+ restore_query_display();
+ close_popup();
+ commit_verbatim(move(query));
+}
- auto query = m_query;
- restore_query_display();
- close_popup();
- commit_verbatim(move(query));
- return;
- }
+Optional<size_t> Omnibox::suggestion_index_for_return() const
+{
+ if (!m_popup_visible || !m_selection.has_value())
+ return {};
- if (m_popup_query_id == m_active_query_id) {
- activate_selected_suggestion();
- return;
+ if (selection_is_explicit())
+ return m_selection->index;
+
+ // The user edited or deleted a completion, so submit the text as typed instead of the popup's
+ // automatically selected row. Rows the user chose deliberately still win.
+ if (m_user_rejected_completion) {
+ if (m_popup_query_id == m_active_query_id && !completion_is_suppressed() && m_suggestions[m_selection->index].text != m_query)
+ return m_selection->index;
+ return {};
}
// Results must never delay Enter or activate after the user has moved on. If the visible rows are
// stale, commit the exact current input through the browser's normal URL-or-search resolution.
- auto query = m_query;
- restore_query_display();
- close_popup();
- commit_verbatim(move(query));
+ if (m_popup_query_id == m_active_query_id)
+ return m_selection->index;
+ return {};
+}
+
+Optional<AutocompleteSuggestion const&> Omnibox::suggestion_for_return() const
+{
+ auto index = suggestion_index_for_return();
+ if (!index.has_value())
+ return {};
+ return m_suggestions[*index];
}
// The chrome dismissed the popup without a key press (for example a click elsewhere in the window).
diff --git a/Libraries/LibWebView/Omnibox.h b/Libraries/LibWebView/Omnibox.h
index b9256071cb6..ac28b0eafe3 100644
--- a/Libraries/LibWebView/Omnibox.h
+++ b/Libraries/LibWebView/Omnibox.h
@@ -103,6 +103,12 @@ public:
return m_selection.map([](auto const& selection) { return selection.index; });
}
+ // Whether the text on display is inline completed to a suggestion.
+ bool is_inline_completed() const { return m_provenance == TextProvenance::InlineCompleted; }
+ // Whether the suggestions for the text as it now stands have yet to arrive.
+ bool has_pending_suggestions() const { return m_active_query_id.has_value() && m_active_query_id != m_popup_query_id; }
+ // The suggestion that pressing Return would go to, if it would not go to the text as typed.
+ Optional<AutocompleteSuggestion const&> suggestion_for_return() const;
// The title of the page the text on display is inline completed to, if it has one.
Optional<String> completion_title() const;
@@ -149,6 +155,7 @@ private:
void highlight_suggestion(size_t suggestion_index, Selection::Origin);
void display_suggestion(size_t suggestion_index);
void activate_selected_suggestion();
+ Optional<size_t> suggestion_index_for_return() const;
void commit_suggestion(size_t suggestion_index, bool record_engagement, bool was_explicit);
void commit_suggestion_text(String, OmniboxDestinationKind);
void commit_verbatim(String);