### 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
text_edit->set_caret_column(0);
	CHECK(text_edit->get_word_under_caret() == "Lorem");
	text_edit->set_caret_column(4);
	CHECK(text_edit->get_word_under_caret() == "Lorem");
	
	text_edit->set_caret_column(5);
	CHECK(text_edit->get_word_under_caret() == "");
	text_edit->set_caret_column(6);
	CHECK(text_edit->get_word_under_caret() == "");
	text_edit->set_caret_line(1);
	CHECK(text_edit->get_caret_line() == 1);
	text_edit->set_caret_line(-1);
	CHECK(text_edit->get_caret_line() == 0);
	text_edit->set_caret_line(100);
	CHECK(text_edit->get_caret_line() == 3);
	text_edit->set_caret_column(-1);
	CHECK(text_edit->get_caret_column() == 0);
	text_edit->set_caret_column(10000000);
	CHECK(text_edit->get_caret_column() == 141);
	memdelete(text_edit);
}
TEST_CASE("[SceneTree][TextEdit] multicaret") {
	TextEdit *text_edit = memnew(TextEdit);
	SceneTree::get_singleton()->get_root()->add_child(text_edit);
	text_edit->set_multiple_carets_enabled(true);
	Array empty_signal_args;
	empty_signal_args.push_back(Array());
	SIGNAL_WATCH(text_edit, "caret_changed");
	text_edit->set_text("this is\nsome test\ntext");
	text_edit->set_caret_line(0);