From fa7e6ddb83699364fd4e35b43702926a55fadf82 Mon Sep 17 00:00:00 2001 From: Manuel Dun Date: Sun, 16 Apr 2023 15:37:36 -0400 Subject: [PATCH] Fix auto-indentation in typed arrays, comments, and after colon Now the editor won't add indentation when pressing enter, is declaring typed variables and there is a colon in the comment example: var a:=0#:[press enter] no indentation --- scene/gui/code_edit.cpp | 2 +- tests/scene/test_code_edit.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 60fe0c32b67..8234c5cf440 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -1075,7 +1075,7 @@ void CodeEdit::_new_line(bool p_split_current_line, bool p_above) { for (; line_col < cc; line_col++) { char32_t c = line[line_col]; - if (auto_indent_prefixes.has(c)) { + if (auto_indent_prefixes.has(c) && is_in_comment(cl, line_col) == -1) { should_indent = true; indent_char = c; continue; diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index c681c768463..c5407d4bcd3 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -2300,6 +2300,17 @@ TEST_CASE("[SceneTree][CodeEdit] indent") { SEND_GUI_ACTION("ui_text_newline_blank"); CHECK(code_edit->get_line(0) == "test{}"); CHECK(code_edit->get_line(1) == ""); + + /* If there is something after a colon + and there is a colon in the comment it + should not indent. */ + code_edit->add_comment_delimiter("#", ""); + code_edit->set_text(""); + code_edit->insert_text_at_caret("test:test#:"); + SEND_GUI_ACTION("ui_text_newline"); + CHECK(code_edit->get_line(0) == "test:test#:"); + CHECK(code_edit->get_line(1) == ""); + code_edit->remove_comment_delimiter("#"); } }