Fix whole word search missing occurences
This commit is contained in:
parent
37ca542d2b
commit
3af5dfbbf3
@ -4467,6 +4467,9 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
|
|||||||
|
|
||||||
int pos_from = 0;
|
int pos_from = 0;
|
||||||
int last_pos = -1;
|
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) {
|
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 (p_search_flags & SEARCH_BACKWARDS) {
|
||||||
@ -4486,11 +4489,21 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
|
|||||||
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)) {
|
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
|
||||||
//validate for whole words
|
//validate for whole words
|
||||||
if (pos > 0 && _is_text_char(text_line[pos - 1]))
|
if (pos > 0 && _is_text_char(text_line[pos - 1]))
|
||||||
pos = -1;
|
is_match = false;
|
||||||
else if (_is_text_char(text_line[pos + p_key.length()]))
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos_from = pos + 1;
|
||||||
pos = -1;
|
pos = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user