You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-06 17:25:19 +00:00
"Whole Words" search can detect word boundaries inside the search term.
For example, searching for ".func" will now match in "a.func" even with Whole Words enabled.
(cherry picked from commit 676627e1d1)
This commit is contained in:
committed by
Yuri Sizov
parent
222cba2aab
commit
04bd9cc06c
@@ -4131,6 +4131,9 @@ Point2i TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_fro
|
||||
int line = p_from_line;
|
||||
int pos = -1;
|
||||
|
||||
bool key_start_is_symbol = is_symbol(p_key[0]);
|
||||
bool key_end_is_symbol = is_symbol(p_key[p_key.length() - 1]);
|
||||
|
||||
for (int i = 0; i < text.size() + 1; i++) {
|
||||
if (line < 0) {
|
||||
line = text.size() - 1;
|
||||
@@ -4194,9 +4197,9 @@ Point2i TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_fro
|
||||
|
||||
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
|
||||
// Validate for whole words.
|
||||
if (pos > 0 && !is_symbol(text_line[pos - 1])) {
|
||||
if (!key_start_is_symbol && pos > 0 && !is_symbol(text_line[pos - 1])) {
|
||||
is_match = false;
|
||||
} else if (pos + p_key.length() < text_line.length() && !is_symbol(text_line[pos + p_key.length()])) {
|
||||
} else if (!key_end_is_symbol && pos + p_key.length() < text_line.length() && !is_symbol(text_line[pos + p_key.length()])) {
|
||||
is_match = false;
|
||||
}
|
||||
}
|
||||
@@ -6990,6 +6993,9 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
|
||||
p_from_column = 0;
|
||||
}
|
||||
|
||||
bool key_start_is_symbol = is_symbol(p_key[0]);
|
||||
bool key_end_is_symbol = is_symbol(p_key[p_key.length() - 1]);
|
||||
|
||||
while (col == -1 && p_from_column <= p_search.length()) {
|
||||
if (p_search_flags & SEARCH_MATCH_CASE) {
|
||||
col = p_search.find(p_key, p_from_column);
|
||||
@@ -7001,9 +7007,9 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
|
||||
if (col != -1 && p_search_flags & SEARCH_WHOLE_WORDS) {
|
||||
p_from_column = col;
|
||||
|
||||
if (col > 0 && !is_symbol(p_search[col - 1])) {
|
||||
if (!key_start_is_symbol && col > 0 && !is_symbol(p_search[col - 1])) {
|
||||
col = -1;
|
||||
} else if ((col + p_key.length()) < p_search.length() && !is_symbol(p_search[col + p_key.length()])) {
|
||||
} else if (!key_end_is_symbol && (col + p_key.length()) < p_search.length() && !is_symbol(p_search[col + p_key.length()])) {
|
||||
col = -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user