diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-12-20 15:07:52 +0100 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-12-20 15:07:52 +0100 |
commit | 02bc2a37dd5927f178ba96e08edb9a75a044b285 (patch) | |
tree | 35771c2c937ff316c92178f9638e8b4797e5870a /tests | |
parent | aae58cd6880cf76555cb9a49cf6b1e8c71692ce0 (diff) | |
parent | 4b82cacc219266cdb16c59f037766e1fc8d25d47 (diff) | |
download | redot-engine-02bc2a37dd5927f178ba96e08edb9a75a044b285.tar.gz |
Merge pull request #86118 from TheSofox/complex-undo-select-fix
Fix so undoing complex operations in `TextEdit` will restore selections
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scene/test_text_edit.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index e81578a862..8f603c698d 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -3186,6 +3186,60 @@ TEST_CASE("[SceneTree][TextEdit] versioning") { CHECK(text_edit->get_version() == 3); // Should this be cleared? CHECK(text_edit->get_saved_version() == 0); + SUBCASE("[TextEdit] versioning selection") { + text_edit->set_text("Godot Engine\nWaiting for Godot\nTest Text for multi carat\nLine 4 Text"); + text_edit->set_multiple_carets_enabled(true); + + text_edit->remove_secondary_carets(); + text_edit->deselect(); + text_edit->set_caret_line(0); + text_edit->set_caret_column(0); + + CHECK(text_edit->get_caret_count() == 1); + + Array caret_index; + caret_index.push_back(0); + + for (int i = 1; i < 4; i++) { + caret_index.push_back(text_edit->add_caret(i, 0)); + CHECK((int)caret_index.back() >= 0); + } + + CHECK(text_edit->get_caret_count() == 4); + + for (int i = 0; i < 4; i++) { + text_edit->select(i, 0, i, 5, caret_index[i]); + } + + CHECK(text_edit->get_caret_count() == 4); + for (int i = 0; i < 4; i++) { + CHECK(text_edit->has_selection(caret_index[i])); + CHECK(text_edit->get_selection_from_line(caret_index[i]) == i); + CHECK(text_edit->get_selection_from_column(caret_index[i]) == 0); + CHECK(text_edit->get_selection_to_line(caret_index[i]) == i); + CHECK(text_edit->get_selection_to_column(caret_index[i]) == 5); + } + text_edit->begin_complex_operation(); + text_edit->deselect(); + text_edit->set_text("New Line Text"); + text_edit->select(0, 0, 0, 7, 0); + text_edit->end_complex_operation(); + + CHECK(text_edit->get_caret_count() == 1); + CHECK(text_edit->get_selected_text(0) == "New Lin"); + + text_edit->undo(); + + CHECK(text_edit->get_caret_count() == 4); + for (int i = 0; i < 4; i++) { + CHECK(text_edit->has_selection(caret_index[i])); + CHECK(text_edit->get_selection_from_line(caret_index[i]) == i); + CHECK(text_edit->get_selection_from_column(caret_index[i]) == 0); + CHECK(text_edit->get_selection_to_line(caret_index[i]) == i); + CHECK(text_edit->get_selection_to_column(caret_index[i]) == 5); + } + } + memdelete(text_edit); } |