### 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
}
		SUBCASE("[TextEdit] select and deselect") {
			text_edit->set_text("this is some text\nfor selection");
			MessageQueue::get_singleton()->flush();
			text_edit->select(-1, -1, 500, 500);
			CHECK(text_edit->has_selection());
			CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
			text_edit->deselect();
			CHECK_FALSE(text_edit->has_selection());
			text_edit->select(500, 500, -1, -1);
			CHECK(text_edit->has_selection());
			CHECK(text_edit->get_selected_text() == "this is some text\nfor selection");
			text_edit->deselect();
			CHECK_FALSE(text_edit->has_selection());
			text_edit->select(0, 4, 0, 8);
			CHECK(text_edit->has_selection());
			CHECK(text_edit->get_selected_text() == " is ");
			text_edit->deselect();
			CHECK_FALSE(text_edit->has_selection());
			text_edit->select(0, 8, 0, 4);
			CHECK(text_edit->has_selection());
			CHECK(text_edit->get_selected_text() == " is ");
			text_edit->set_selecting_enabled(false);
			CHECK_FALSE(text_edit->has_selection());
			text_edit->select(0, 8, 0, 4);
			CHECK_FALSE(text_edit->has_selection());
			text_edit->set_selecting_enabled(true);
			text_edit->select(0, 8, 0, 4);
			CHECK(text_edit->has_selection());
			SEND_GUI_ACTION("ui_text_caret_right");