LibWeb: Add WrapAround option to find in page

This allows `Page::find_in_page()` to optionally not return a result if
the start or end of the document has been reached.
This commit is contained in:
Tim Ledbetter 2024-06-25 22:18:49 +01:00 committed by Andreas Kling
parent fee7b4147c
commit cda31615da
Notes: sideshowbarker 2024-07-16 17:05:37 +09:00
2 changed files with 15 additions and 4 deletions

View File

@ -619,15 +619,21 @@ Page::FindInPageResult Page::perform_find_in_page_query(FindInPageQuery const& q
if (direction.has_value()) {
if (direction.value() == SearchDirection::Forward) {
if (m_find_in_page_match_index >= all_matches.size() - 1)
if (m_find_in_page_match_index >= all_matches.size() - 1) {
if (query.wrap_around == WrapAround::No)
return {};
m_find_in_page_match_index = 0;
else
} else {
m_find_in_page_match_index++;
}
} else {
if (m_find_in_page_match_index == 0)
if (m_find_in_page_match_index == 0) {
if (query.wrap_around == WrapAround::No)
return {};
m_find_in_page_match_index = all_matches.size() - 1;
else
} else {
m_find_in_page_match_index--;
}
}
}

View File

@ -190,9 +190,14 @@ public:
void clear_selection();
enum class WrapAround {
Yes,
No,
};
struct FindInPageQuery {
String string {};
CaseSensitivity case_sensitivity { CaseSensitivity::CaseInsensitive };
WrapAround wrap_around { WrapAround::Yes };
};
struct FindInPageResult {
size_t current_match_index { 0 };