summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.cpp10
-rw-r--r--Userland/Libraries/LibGUI/TextDocument.h4
2 files changed, 8 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp
index 3c1836184e..a523b18157 100644
--- a/Userland/Libraries/LibGUI/TextDocument.cpp
+++ b/Userland/Libraries/LibGUI/TextDocument.cpp
@@ -387,7 +387,7 @@ void TextDocument::update_regex_matches(const StringView& needle)
}
}
-TextRange TextDocument::find_next(const StringView& needle, const TextPosition& start, SearchShouldWrap should_wrap, bool regmatch)
+TextRange TextDocument::find_next(const StringView& needle, const TextPosition& start, SearchShouldWrap should_wrap, bool regmatch, bool match_case)
{
if (needle.is_empty())
return {};
@@ -450,7 +450,7 @@ TextRange TextDocument::find_next(const StringView& needle, const TextPosition&
do {
auto ch = code_point_at(position);
// FIXME: This is not the right way to use a Unicode needle!
- if (ch == (u32)needle[needle_index]) {
+ if (match_case ? ch == (u32)needle[needle_index] : tolower(ch) == tolower((u32)needle[needle_index])) {
if (needle_index == 0)
start_of_potential_match = position;
++needle_index;
@@ -467,7 +467,7 @@ TextRange TextDocument::find_next(const StringView& needle, const TextPosition&
return {};
}
-TextRange TextDocument::find_previous(const StringView& needle, const TextPosition& start, SearchShouldWrap should_wrap, bool regmatch)
+TextRange TextDocument::find_previous(const StringView& needle, const TextPosition& start, SearchShouldWrap should_wrap, bool regmatch, bool match_case)
{
if (needle.is_empty())
return {};
@@ -524,6 +524,8 @@ TextRange TextDocument::find_previous(const StringView& needle, const TextPositi
TextPosition position = start.is_valid() ? start : TextPosition(0, 0);
position = previous_position_before(position, should_wrap);
+ if (position.line() >= line_count())
+ return {};
TextPosition original_position = position;
TextPosition end_of_potential_match;
@@ -532,7 +534,7 @@ TextRange TextDocument::find_previous(const StringView& needle, const TextPositi
do {
auto ch = code_point_at(position);
// FIXME: This is not the right way to use a Unicode needle!
- if (ch == (u32)needle[needle_index]) {
+ if (match_case ? ch == (u32)needle[needle_index] : tolower(ch) == tolower((u32)needle[needle_index])) {
if (needle_index == needle.length() - 1)
end_of_potential_match = position;
if (needle_index == 0)
diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h
index ba00d34e0d..d559373f9b 100644
--- a/Userland/Libraries/LibGUI/TextDocument.h
+++ b/Userland/Libraries/LibGUI/TextDocument.h
@@ -109,8 +109,8 @@ public:
Vector<TextRange> find_all(const StringView& needle, bool regmatch = false);
void update_regex_matches(const StringView&);
- TextRange find_next(const StringView&, const TextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes, bool regmatch = false);
- TextRange find_previous(const StringView&, const TextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes, bool regmatch = false);
+ TextRange find_next(const StringView&, const TextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes, bool regmatch = false, bool match_case = true);
+ TextRange find_previous(const StringView&, const TextPosition& start = {}, SearchShouldWrap = SearchShouldWrap::Yes, bool regmatch = false, bool match_case = true);
TextPosition next_position_after(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;
TextPosition previous_position_before(const TextPosition&, SearchShouldWrap = SearchShouldWrap::Yes) const;