LibWeb: Limit find in page query to documents in the active window
Previously, refreshing the current page and doing a new find in page query would result in duplicate matches being returned.
This commit is contained in:
parent
33f66dcb8f
commit
077cb7687d
Notes:
sideshowbarker
2024-07-17 06:54:15 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/077cb7687d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/171
2 changed files with 18 additions and 10 deletions
|
@ -538,13 +538,23 @@ void Page::set_user_style(String source)
|
|||
}
|
||||
}
|
||||
|
||||
Vector<JS::Handle<DOM::Document>> Page::documents_in_active_window() const
|
||||
{
|
||||
if (!top_level_traversable_is_initialized())
|
||||
return {};
|
||||
|
||||
auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop();
|
||||
for (ssize_t i = documents.size() - 1; i >= 0; --i) {
|
||||
if (documents[i]->window() != top_level_traversable()->active_window())
|
||||
documents.remove(i);
|
||||
}
|
||||
|
||||
return documents;
|
||||
}
|
||||
|
||||
void Page::clear_selection()
|
||||
{
|
||||
auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop();
|
||||
for (auto const& document : documents) {
|
||||
if (&document->page() != this)
|
||||
continue;
|
||||
|
||||
for (auto const& document : documents_in_active_window()) {
|
||||
auto selection = document->get_selection();
|
||||
if (!selection)
|
||||
continue;
|
||||
|
@ -563,12 +573,8 @@ Page::FindInPageResult Page::find_in_page(String const& query, CaseSensitivity c
|
|||
return {};
|
||||
}
|
||||
|
||||
auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop();
|
||||
Vector<JS::Handle<DOM::Range>> all_matches;
|
||||
for (auto const& document : documents) {
|
||||
if (&document->page() != this)
|
||||
continue;
|
||||
|
||||
for (auto const& document : documents_in_active_window()) {
|
||||
auto matches = document->find_matching_text(query, case_sensitivity);
|
||||
all_matches.extend(move(matches));
|
||||
}
|
||||
|
|
|
@ -201,6 +201,8 @@ private:
|
|||
|
||||
JS::GCPtr<HTML::HTMLMediaElement> media_context_menu_element();
|
||||
|
||||
Vector<JS::Handle<DOM::Document>> documents_in_active_window() const;
|
||||
|
||||
void update_find_in_page_selection();
|
||||
|
||||
JS::NonnullGCPtr<PageClient> m_client;
|
||||
|
|
Loading…
Add table
Reference in a new issue