Merge pull request #17438 from Deluvi/get-word-pos-quote-fix

get_word_at_pos considers simple and double quotes
This commit is contained in:
Max Hilbrunner 2018-07-03 18:28:47 +02:00 committed by GitHub
commit fbff1804d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {
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 {
} else if (!inside_quotes) {
qbegin = i + 1;
inside_quotes = true;
selected_quote = s[i];
}
}
}
}