diff options
author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2018-07-03 18:28:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-03 18:28:47 +0200 |
commit | fbff1804d24009a9f909762f55448f24de1aeb7e (patch) | |
tree | 6985dac63634502576da5173cdb42e6af72e0bd5 /scene | |
parent | b21c1f64cdbbb762e6ede25eed1fbd1dec4b91a6 (diff) | |
parent | 215150cfbfdb8ed9696c18a4e544cde63910bded (diff) |
Merge pull request #17438 from Deluvi/get-word-pos-quote-fix
get_word_at_pos considers simple and double quotes
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/text_edit.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4fe06e9a4c..327c236f8c 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -5774,18 +5774,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; } } } |