### 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
Control::_update_theme_item_cache();
	theme_cache.base_scale = get_theme_default_base_scale();
	use_selected_font_color = theme_cache.font_selected_color != Color(0, 0, 0, 0);
	if (text.get_line_height() + theme_cache.line_spacing < 1) {
		WARN_PRINT("Line height is too small, please increase font_size and/or line_spacing");
	}
}
void TextEdit::_update_caches() {
	
	TextServer::Direction dir;
	if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
		dir = is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR;
	} else {
		dir = (TextServer::Direction)text_direction;
	}
	text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale());
	text.set_draw_control_chars(draw_control_chars);
	text.set_font(theme_cache.font);
	text.set_font_size(theme_cache.font_size);
	text.invalidate_font();
	_update_placeholder();
	
	if (syntax_highlighter.is_valid()) {
		syntax_highlighter->set_text_edit(this);
	}
}
Size2 TextEdit::get_minimum_size() const {