summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorMarian <marian.sabat@centrum.sk>2019-10-25 15:01:43 +0200
committerMarian <marian.sabat@centrum.sk>2019-10-25 15:01:43 +0200
commit616f02e90576c899e34e9810d2dcbfa606abd4b6 (patch)
treedeb2580430941a74a9a3e9e1da7ab4f589d42993 /scene
parentf259beb4f1d8c9f2417c5a80deed2ae68baa69fa (diff)
Fixed indenting issue with comment at end of line
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/text_edit.cpp61
1 files changed, 41 insertions, 20 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index a7e87a28ae..738cd4f988 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2849,27 +2849,48 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// 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) {
- 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";
- }
+ const Map<int, Text::ColorRegionInfo> &cri_map = text.get_color_region_info(cursor.line);
+ bool indent_char_found = false;
+ bool should_indent = false;
+ char indent_char;
+ char c;
+
+ for (int i = 0; i < cursor.column; i++) {
+ c = text[cursor.line][i];
+ switch (c) {
+ case ':':
+ case '{':
+ case '[':
+ case '(':
+ indent_char_found = true;
+ should_indent = true;
+ indent_char = c;
+ continue;
+ }
- // 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;
+ if (indent_char_found && cri_map.has(i) && (color_regions[cri_map[i].region].begin_key == "#" || color_regions[cri_map[i].region].begin_key == "//")) {
+
+ should_indent = true;
+ break;
+ } else if (indent_char_found && !_is_whitespace(c)) {
+ should_indent = false;
+ indent_char_found = false;
+ }
+ }
+
+ if (!is_line_comment(cursor.line) && should_indent) {
+ 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.
+ char closing_char = _get_right_pair_symbol(indent_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);
+ }
}
}
}