diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp index 0379e50dfb..8e0f8fd8ce 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp @@ -54,36 +54,7 @@ InProcessWebView::~InProcessWebView() void InProcessWebView::select_all() { - auto* layout_root = this->layout_root(); - if (!layout_root) - return; - - const Layout::Node* first_layout_node = layout_root; - - for (;;) { - auto* next = first_layout_node->next_in_pre_order(); - if (!next) - break; - first_layout_node = next; - if (is(*first_layout_node)) - break; - } - - const Layout::Node* last_layout_node = first_layout_node; - - for (const Layout::Node* layout_node = first_layout_node; layout_node; layout_node = layout_node->next_in_pre_order()) { - if (is(*layout_node)) - last_layout_node = layout_node; - } - - VERIFY(first_layout_node); - VERIFY(last_layout_node); - - int last_layout_node_index_in_node = 0; - if (is(*last_layout_node)) - last_layout_node_index_in_node = verify_cast(*last_layout_node).text_for_rendering().length() - 1; - - layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } }); + page().focused_context().select_all(); update(); } diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp index 17b5f47876..70d9beeb4b 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp @@ -275,6 +275,42 @@ String BrowsingContext::selected_text() const return builder.to_string(); } +void BrowsingContext::select_all() +{ + if (!m_document) + return; + auto* layout_root = m_document->layout_node(); + if (!layout_root) + return; + + const Layout::Node* first_layout_node = layout_root; + + for (;;) { + auto* next = first_layout_node->next_in_pre_order(); + if (!next) + break; + first_layout_node = next; + if (is(*first_layout_node)) + break; + } + + const Layout::Node* last_layout_node = first_layout_node; + + for (const Layout::Node* layout_node = first_layout_node; layout_node; layout_node = layout_node->next_in_pre_order()) { + if (is(*layout_node)) + last_layout_node = layout_node; + } + + VERIFY(first_layout_node); + VERIFY(last_layout_node); + + int last_layout_node_index_in_node = 0; + if (is(*last_layout_node)) + last_layout_node_index_in_node = verify_cast(*last_layout_node).text_for_rendering().length() - 1; + + layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } }); +} + void BrowsingContext::register_viewport_client(ViewportClient& client) { auto result = m_viewport_clients.set(&client); diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.h b/Userland/Libraries/LibWeb/Page/BrowsingContext.h index df89a12c6d..77229647a2 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.h @@ -80,6 +80,7 @@ public: bool cursor_blink_state() const { return m_cursor_blink_state; } String selected_text() const; + void select_all(); void did_edit(Badge);