summaryrefslogtreecommitdiffstats
path: root/scene/gui/text_edit.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-10-05 10:08:58 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-10-05 10:08:58 +0200
commitaa554e82785ff4c446532f121427c6ea6b4d15e6 (patch)
tree0a1e834a0b19647a6586f5e25db6c87ac5065757 /scene/gui/text_edit.cpp
parent829d9bb6ba24ad955ac8fd29a88ed25572adc1dd (diff)
parent676627e1d16367616c7022df8d12c836c201c5f4 (diff)
downloadredot-engine-aa554e82785ff4c446532f121427c6ea6b4d15e6.tar.gz
Merge pull request #82694 from BrianMacIntosh/master
"Whole Words" search can detect word boundaries inside the search term.
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r--scene/gui/text_edit.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 1642d19b67..3d426b8bf3 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -4112,6 +4112,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;
@@ -4175,9 +4178,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;
}
}
@@ -7022,6 +7025,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);
@@ -7038,9 +7044,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;
}
}