1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Merge pull request #36715 from dreamsComeTrue/fix-text-edit-comment-quotes

Allow single quotes [',"] in comments in TextEdit
This commit is contained in:
Rémi Verschelde
2020-03-11 07:32:24 +01:00
committed by GitHub

View File

@@ -1856,6 +1856,7 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
bool in_single_quote = false; bool in_single_quote = false;
bool in_double_quote = false; bool in_double_quote = false;
bool found_comment = false;
int c = 0; int c = 0;
while (c < line.length()) { while (c < line.length()) {
@@ -1865,6 +1866,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
if (cursor.column == c) { if (cursor.column == c) {
break; break;
} }
} else if (!in_single_quote && !in_double_quote && line[c] == '#') {
found_comment = true;
break;
} else { } else {
if (line[c] == '\'' && !in_double_quote) { if (line[c] == '\'' && !in_double_quote) {
in_single_quote = !in_single_quote; in_single_quote = !in_single_quote;
@@ -1880,6 +1884,14 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
} }
} }
// Do not need to duplicate quotes while in comments
if (found_comment) {
insert_text_at_cursor(ch_single);
cursor_set_column(cursor_position_to_move);
return;
}
// Disallow inserting duplicated quotes while already in string // Disallow inserting duplicated quotes while already in string
if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) { if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) {
insert_text_at_cursor(ch_single); insert_text_at_cursor(ch_single);