Merge pull request #33066 from Tabas32/fix_indentation
Fixed indenting issue with comment at end of line
This commit is contained in:
commit
2751cea0d4
@ -2860,27 +2860,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 = text[cursor.line][cursor.column];
|
||||
|
||||
// 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;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user