### Godot version

v4.0.beta.custom_build [13f0158]

### System information

Windows 10

### Issue description

When doing operations (`begin_complex_operation` and `end_complex_operation`) with multiple selections in TextEdit, some of these selections don't revert upon undo. This behavior is affects some of script editor's operations, like duplicate selection and delete lines.

### Steps to reproduce

Open script editor, make multiple selections. Keep in mind what you have selected. Do duplicate selection (ctrl+shift+D). Undo (ctrl+Z). Compare the result to what you remember.

### Minimal reproduction project

N/A
MessageQueue::get_singleton()->flush();
	CHECK(text_edit->get_first_visible_line() == 5);
	SEND_GUI_KEY_EVENT(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);
}
TEST_CASE("[SceneTree][TextEdit] setter getters") {
	TextEdit *text_edit = memnew(TextEdit);
	SceneTree::get_singleton()->get_root()->add_child(text_edit);
	SUBCASE("[TextEdit] set and get placeholder") {
		text_edit->set_placeholder("test\nplaceholder");
		CHECK(text_edit->get_placeholder() == "test\nplaceholder");
		CHECK(text_edit->get_text() == "");
		CHECK(text_edit->get_line_count() == 1);
		CHECK(text_edit->get_last_full_visible_line() == 0);
	}
	SUBCASE("[TextEdit] highlight current line") {
		text_edit->set_highlight_current_line(true);