mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-30 21:28:59 +00:00
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:
parent
fee7b4147c
commit
cda31615da
Notes:
sideshowbarker
2024-07-16 17:05:37 +09:00
Author: https://github.com/tcl3
Commit: cda31615da
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/293
2 changed files with 15 additions and 4 deletions
|
@ -619,15 +619,21 @@ Page::FindInPageResult Page::perform_find_in_page_query(FindInPageQuery const& q
|
||||||
|
|
||||||
if (direction.has_value()) {
|
if (direction.has_value()) {
|
||||||
if (direction.value() == SearchDirection::Forward) {
|
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;
|
m_find_in_page_match_index = 0;
|
||||||
else
|
} else {
|
||||||
m_find_in_page_match_index++;
|
m_find_in_page_match_index++;
|
||||||
|
}
|
||||||
} else {
|
} 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;
|
m_find_in_page_match_index = all_matches.size() - 1;
|
||||||
else
|
} else {
|
||||||
m_find_in_page_match_index--;
|
m_find_in_page_match_index--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,9 +190,14 @@ public:
|
||||||
|
|
||||||
void clear_selection();
|
void clear_selection();
|
||||||
|
|
||||||
|
enum class WrapAround {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
};
|
||||||
struct FindInPageQuery {
|
struct FindInPageQuery {
|
||||||
String string {};
|
String string {};
|
||||||
CaseSensitivity case_sensitivity { CaseSensitivity::CaseInsensitive };
|
CaseSensitivity case_sensitivity { CaseSensitivity::CaseInsensitive };
|
||||||
|
WrapAround wrap_around { WrapAround::Yes };
|
||||||
};
|
};
|
||||||
struct FindInPageResult {
|
struct FindInPageResult {
|
||||||
size_t current_match_index { 0 };
|
size_t current_match_index { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue