diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2022-10-16 15:06:13 +0100 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2022-10-16 19:30:03 +0100 |
commit | 4bfb1d953c5960701a07fd0ca15852dd12332359 (patch) | |
tree | e53684ea36d6b465b2a6533ed2589ea37af08c7a | |
parent | 3a59c833f1b7e34ddef57522800288a0dee8562d (diff) |
Fix undo redo not adjusting TextEdit viewport to caret
-rw-r--r-- | scene/gui/text_edit.cpp | 4 | ||||
-rw-r--r-- | tests/scene/test_text_edit.h | 26 |
2 files changed, 28 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4cd244306c..90974e31df 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3863,7 +3863,7 @@ void TextEdit::undo() { } caret_pos_dirty = true; } - queue_redraw(); + adjust_viewport_to_caret(); } void TextEdit::redo() { @@ -3915,7 +3915,7 @@ void TextEdit::redo() { } caret_pos_dirty = true; } - queue_redraw(); + adjust_viewport_to_caret(); } void TextEdit::clear_undo_history() { diff --git a/tests/scene/test_text_edit.h b/tests/scene/test_text_edit.h index 3a20ac123b..2ef0a3345f 100644 --- a/tests/scene/test_text_edit.h +++ b/tests/scene/test_text_edit.h @@ -3918,6 +3918,32 @@ TEST_CASE("[SceneTree][TextEdit] viewport") { CHECK(text_edit->get_last_full_visible_line_wrap_index() == 0); CHECK(text_edit->get_caret_wrap_index() == 0); + // Typing and undo / redo should adjust viewport + text_edit->set_caret_line(0); + text_edit->set_caret_column(0); + text_edit->set_line_as_first_visible(5); + MessageQueue::get_singleton()->flush(); + CHECK(text_edit->get_first_visible_line() == 5); + + SEND_GUI_KEY_EVENT(text_edit, Key::A); + CHECK(text_edit->get_first_visible_line() == 0); + + text_edit->set_line_as_first_visible(5); + MessageQueue::get_singleton()->flush(); + CHECK(text_edit->get_first_visible_line() == 5); + + text_edit->undo(); + MessageQueue::get_singleton()->flush(); + CHECK(text_edit->get_first_visible_line() == 0); + + text_edit->set_line_as_first_visible(5); + MessageQueue::get_singleton()->flush(); + CHECK(text_edit->get_first_visible_line() == 5); + + text_edit->redo(); + MessageQueue::get_singleton()->flush(); + CHECK(text_edit->get_first_visible_line() == 0); + memdelete(text_edit); } |