summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeluvi <noe.baylac@protonmail.com>2018-03-11 13:59:48 +0100
committerDeluvi <noe.baylac@protonmail.com>2018-05-09 08:33:57 +0200
commit215150cfbfdb8ed9696c18a4e544cde63910bded (patch)
tree7de0c13d5f283c8598c536e3fba60dffff07fbb4
parent0f930f831410bc57d0e975b4ab73715d0d034735 (diff)
get_word_at_pos considers simple and double quotes
When using the get_word_at_pos function in TextEdit, the function would return a full string only if this string is surrounded by double quotes and not by simple quotes. With this fix, get_word_at_pos will return the full string, whether be a string surrounded by simple or double quotes. Fixes #17437
-rw-r--r--scene/gui/text_edit.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 4c9f515ced..87497ae489 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -5376,18 +5376,23 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
if (select_word(s, col, beg, end)) {
bool inside_quotes = false;
+ char selected_quote = '\0';
int qbegin = 0, qend = 0;
for (int i = 0; i < s.length(); i++) {
- if (s[i] == '"') {
- if (inside_quotes) {
- qend = i;
- inside_quotes = false;
- if (col >= qbegin && col <= qend) {
- return s.substr(qbegin, qend - qbegin);
+ if (s[i] == '"' || s[i] == '\'') {
+ if (i == 0 || s[i - 1] != '\\') {
+ if (inside_quotes && selected_quote == s[i]) {
+ qend = i;
+ inside_quotes = false;
+ selected_quote = '\0';
+ if (col >= qbegin && col <= qend) {
+ return s.substr(qbegin, qend - qbegin);
+ }
+ } else if (!inside_quotes) {
+ qbegin = i + 1;
+ inside_quotes = true;
+ selected_quote = s[i];
}
- } else {
- qbegin = i + 1;
- inside_quotes = true;
}
}
}