summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-01-08 22:59:16 +0100
committerGitHub <noreply@github.com>2018-01-08 22:59:16 +0100
commit4b414f45c47d699da4442ac2347c3b1684616cc0 (patch)
treebaa92d07597a189d3ad4590b0a2bf7c95e0bd328
parent99da4669795525001250ae4e170f59d9c0e6c53f (diff)
parent3af5dfbbf30a212f4b1b409cd0eb7c0bdcd8e257 (diff)
Merge pull request #15507 from poke1024/fix15106
Fix whole word search missing occurences
-rw-r--r--scene/gui/text_edit.cpp45
1 files changed, 29 insertions, 16 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index a3f59b54fc..f686dc52a0 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -4467,31 +4467,44 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
int pos_from = 0;
int last_pos = -1;
- while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.find(p_key, pos_from) : text_line.findn(p_key, pos_from)) != -1) {
- if (p_search_flags & SEARCH_BACKWARDS) {
+ while (true) {
- if (last_pos > from_column)
- break;
- pos = last_pos;
+ while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.find(p_key, pos_from) : text_line.findn(p_key, pos_from)) != -1) {
- } else {
+ if (p_search_flags & SEARCH_BACKWARDS) {
- if (last_pos >= from_column) {
+ if (last_pos > from_column)
+ break;
pos = last_pos;
- break;
+
+ } else {
+
+ if (last_pos >= from_column) {
+ pos = last_pos;
+ break;
+ }
}
+
+ pos_from = last_pos + p_key.length();
}
- pos_from = last_pos + p_key.length();
- }
+ bool is_match = true;
+
+ if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
+ //validate for whole words
+ if (pos > 0 && _is_text_char(text_line[pos - 1]))
+ is_match = false;
+ else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()]))
+ is_match = false;
+ }
+
+ if (is_match || last_pos == -1 || pos == -1) {
+ break;
+ }
- if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
- //validate for whole words
- if (pos > 0 && _is_text_char(text_line[pos - 1]))
- pos = -1;
- else if (_is_text_char(text_line[pos + p_key.length()]))
- pos = -1;
+ pos_from = pos + 1;
+ pos = -1;
}
if (pos != -1)