### 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
if (draw_caret_when_editable_disabled == p_enable) {
		return;
	}
	draw_caret_when_editable_disabled = p_enable;
	queue_redraw();
}
bool TextEdit::is_drawing_caret_when_editable_disabled() const {
	return draw_caret_when_editable_disabled;
}
void TextEdit::set_move_caret_on_right_click_enabled(const bool p_enabled) {
	move_caret_on_right_click = p_enabled;
}
bool TextEdit::is_move_caret_on_right_click_enabled() const {
	return move_caret_on_right_click;
}
void TextEdit::set_caret_mid_grapheme_enabled(const bool p_enabled) {
	caret_mid_grapheme_enabled = p_enabled;
}
bool TextEdit::is_caret_mid_grapheme_enabled() const {
	return caret_mid_grapheme_enabled;
}
void TextEdit::set_multiple_carets_enabled(bool p_enabled) {
	multi_carets_enabled = p_enabled;
	if (!multi_carets_enabled) {
		remove_secondary_carets();
	}
}
bool TextEdit::is_multiple_carets_enabled() const {