### 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
ERR_FAIL_INDEX(p_gutter, gutters.size());
	gutters.remove_at(p_gutter);
	text.remove_gutter(p_gutter);
	_update_gutter_width();
	emit_signal(SNAME("gutter_removed"));
	queue_redraw();
}
int TextEdit::get_gutter_count() const {
	return gutters.size();
}
void TextEdit::set_gutter_name(int p_gutter, const String &p_name) {
	ERR_FAIL_INDEX(p_gutter, gutters.size());
	gutters.write[p_gutter].name = p_name;
}
String TextEdit::get_gutter_name(int p_gutter) const {
	ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
	return gutters[p_gutter].name;
}
void TextEdit::set_gutter_type(int p_gutter, GutterType p_type) {
	ERR_FAIL_INDEX(p_gutter, gutters.size());
	if (gutters[p_gutter].type == p_type) {
		return;
	}
	gutters.write[p_gutter].type = p_type;
	queue_redraw();
}
TextEdit::GutterType TextEdit::get_gutter_type(int p_gutter) const {