### 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
remove_secondary_carets();
	if (p_select) {
		_pre_shift_selection(0);
	} else {
		deselect();
	}
	set_caret_line(get_last_unhidden_line(), true, false, 9999);
	set_caret_column(text[get_caret_line()].length());
	if (p_select) {
		_post_shift_selection(0);
	}
}
bool TextEdit::_clear_carets_and_selection() {
	if (get_caret_count() > 1) {
		remove_secondary_carets();
		return true;
	}
	if (has_selection()) {
		deselect();
		return true;
	}
	return false;
}
void TextEdit::_get_above_below_caret_line_column(int p_old_line, int p_old_wrap_index, int p_old_column, bool p_below, int &p_new_line, int &p_new_column, int p_last_fit_x) const {