diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2021-02-21 19:01:26 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-22 09:21:30 +0100 |
commit | 3e987eba2b39b137a78aafbfc6340eb375f219a6 (patch) | |
tree | 73a3c186e6df5e5c8ee8adba8e86cd264ed55936 /Userland/Libraries/LibGUI | |
parent | b4c0314f1dae98fa5d206a097e29a30950d2624f (diff) | |
download | serenity-3e987eba2b39b137a78aafbfc6340eb375f219a6.zip |
TextEditor+LibGUI: Add case matching and wrap around optionality
Adds simple ASCII case matching and wrap around toggles to
TextEditor's find/replace widget and reorganizes its layout
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/TextDocument.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextDocument.h | 4 |
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; |