diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-08-19 16:04:34 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-08-19 16:04:34 +0200 |
commit | db5003519a19ed99d5c7bcc059201f8ace82b162 (patch) | |
tree | e05a55f70673411fb9cae4f19d7068f1434f0aed | |
parent | 80933392f351447b4461f7209fd13998963f8ef8 (diff) | |
parent | 2860b99077fff229927067948bb731cb61464317 (diff) | |
download | redot-engine-db5003519a19ed99d5c7bcc059201f8ace82b162.tar.gz |
Merge pull request #89554 from smnast/backspace-unfold
Fix backspace always unfolding previous line
-rw-r--r-- | scene/gui/code_edit.cpp | 2 | ||||
-rw-r--r-- | tests/scene/test_code_edit.h | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 00b9a3478a..412eb83515 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -765,7 +765,7 @@ void CodeEdit::_backspace_internal(int p_caret) { continue; } - if (to_line > 0 && _is_line_hidden(to_line - 1)) { + if (to_line > 0 && to_column == 0 && _is_line_hidden(to_line - 1)) { unfold_line(to_line - 1); } diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index a166002cdd..9ec1b812df 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -4609,6 +4609,26 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_text() == "line 1\nline 2\nline 3"); CHECK(code_edit->get_caret_line() == 0); CHECK(code_edit->get_caret_column() == 0); + + // Unfold previous folded line on backspace if the caret is at the first column. + code_edit->set_line_folding_enabled(true); + code_edit->set_text("line 1\n\tline 2\nline 3"); + code_edit->set_caret_line(2); + code_edit->set_caret_column(0); + code_edit->fold_line(0); + code_edit->backspace(); + CHECK_FALSE(code_edit->is_line_folded(0)); + code_edit->set_line_folding_enabled(false); + + // Do not unfold previous line on backspace if the caret is not at the first column. + code_edit->set_line_folding_enabled(true); + code_edit->set_text("line 1\n\tline 2\nline 3"); + code_edit->set_caret_line(2); + code_edit->set_caret_column(4); + code_edit->fold_line(0); + code_edit->backspace(); + CHECK(code_edit->is_line_folded(0)); + code_edit->set_line_folding_enabled(false); } SUBCASE("[TextEdit] cut") { |