diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2019-10-18 11:02:05 +0200 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2019-10-18 11:02:05 +0200 |
commit | 74d7cbf9203dc9061385ad34a798c3c8aa02337d (patch) | |
tree | 0319c285d1c9e03d11506ef3bd2c9b5e0ae9e4ae | |
parent | 119bf237209414a49879fba40459f22315ab1467 (diff) |
Auto-indent after opening bracket and parenthesis in the script editor
This change makes auto-indent work the same way as for curly brackets, so '[', '(', '{' all act the same.
Fixes #32897
-rw-r--r-- | scene/gui/text_edit.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 5f9b913e8c..23ac1420e3 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2843,19 +2843,30 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { // No need to indent if we are going upwards. if (auto_indent && !(k->get_command() && k->get_shift())) { - // Indent once again if previous line will end with ':' or '{' and the line is not a comment + // Indent once again if previous line will end with ':','{','[','(' and the line is not a comment // (i.e. colon/brace precedes current cursor position). - if (cursor.column > 0 && (text[cursor.line][cursor.column - 1] == ':' || text[cursor.line][cursor.column - 1] == '{') && !is_line_comment(cursor.line)) { - if (indent_using_spaces) { - ins += space_indent; - } else { - ins += "\t"; - } + if (cursor.column > 0) { + char prev_char = text[cursor.line][cursor.column - 1]; + switch (prev_char) { + case ':': + case '{': + case '[': + case '(': { + if (!is_line_comment(cursor.line)) { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } - // No need to move the brace below if we are not taking the text with us. - if (text[cursor.line][cursor.column] == '}' && !k->get_command()) { - brace_indent = true; - ins += "\n" + ins.substr(1, ins.length() - 2); + // No need to move the brace below if we are not taking the text with us. + char closing_char = _get_right_pair_symbol(prev_char); + if ((closing_char != 0) && (closing_char == text[cursor.line][cursor.column]) && !k->get_command()) { + brace_indent = true; + ins += "\n" + ins.substr(1, ins.length() - 2); + } + } + } break; } } } |