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:
commit
fbff1804d2
1 changed files with 14 additions and 9 deletions
|
@ -5774,18 +5774,23 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
|
||||||
if (select_word(s, col, beg, end)) {
|
if (select_word(s, col, beg, end)) {
|
||||||
|
|
||||||
bool inside_quotes = false;
|
bool inside_quotes = false;
|
||||||
|
char selected_quote = '\0';
|
||||||
int qbegin = 0, qend = 0;
|
int qbegin = 0, qend = 0;
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
if (s[i] == '"') {
|
if (s[i] == '"' || s[i] == '\'') {
|
||||||
if (inside_quotes) {
|
if (i == 0 || s[i - 1] != '\\') {
|
||||||
qend = i;
|
if (inside_quotes && selected_quote == s[i]) {
|
||||||
inside_quotes = false;
|
qend = i;
|
||||||
if (col >= qbegin && col <= qend) {
|
inside_quotes = false;
|
||||||
return s.substr(qbegin, qend - qbegin);
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue