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)) {
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue