summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-09-10 18:52:35 +0200
committerGitHub <noreply@github.com>2018-09-10 18:52:35 +0200
commite883edfac94d03280a75b647fd19ac1cfab120b2 (patch)
treee93b71b64b0e78f1a38d57e813e5d42220a10e66 /scene
parent87e0563116df032dfa89473e2b1253e24cbdc42b (diff)
parente474b4a4447c3a7e1f7e2f35ff77af64623eaa1a (diff)
Merge pull request #21872 from Paulb23/fix_backwards_search
Fix backwards search in TextEdit selecting non-whole words, issue 15677
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/text_edit.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 6dfc77ccae..8f1971c1ee 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -4838,28 +4838,27 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
pos = -1;
- int pos_from = 0;
+ int pos_from = (p_search_flags & SEARCH_BACKWARDS) ? text_line.length() : 0;
int last_pos = -1;
while (true) {
- 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) {
-
- if (last_pos > from_column)
+ if (p_search_flags & SEARCH_BACKWARDS) {
+ while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.rfind(p_key, pos_from) : text_line.rfindn(p_key, pos_from)) != -1) {
+ if (last_pos <= from_column) {
+ pos = last_pos;
break;
- pos = last_pos;
-
- } else {
-
+ }
+ pos_from = last_pos - p_key.length();
+ }
+ } else {
+ 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 (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;
@@ -4872,11 +4871,15 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
is_match = false;
}
+ if (pos_from == -1) {
+ pos = -1;
+ }
+
if (is_match || last_pos == -1 || pos == -1) {
break;
}
- pos_from = pos + 1;
+ pos_from = (p_search_flags & SEARCH_BACKWARDS) ? pos - 1 : pos + 1;
pos = -1;
}