### 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
} else {
		placeholder_data_buf->set_direction((TextServer::Direction)text_direction);
	}
	placeholder_data_buf->set_preserve_control(draw_control_chars);
	placeholder_data_buf->add_string(placeholder_translated, theme_cache.font, theme_cache.font_size, language);
	placeholder_bidi_override = structured_text_parser(st_parser, st_args, placeholder_translated);
	if (placeholder_bidi_override.is_empty()) {
		TS->shaped_text_set_bidi_override(placeholder_data_buf->get_rid(), placeholder_bidi_override);
	}
	if (get_tab_size() > 0) {
		Vector<float> tabs;
		tabs.push_back(theme_cache.font->get_char_size(' ', theme_cache.font_size).width * get_tab_size());
		placeholder_data_buf->tab_align(tabs);
	}
	
	const int wrap_amount = placeholder_data_buf->get_line_count() - 1;
	placeholder_line_height = theme_cache.font->get_height(theme_cache.font_size);
	for (int i = 0; i <= wrap_amount; i++) {
		placeholder_line_height = MAX(placeholder_line_height, placeholder_data_buf->get_line_size(i).y);
	}
	
	placeholder_max_width = placeholder_data_buf->get_size().x;
	
	placeholder_wraped_rows.clear();
	for (int i = 0; i <= wrap_amount; i++) {
		Vector2i line_range = placeholder_data_buf->get_line_range(i);
		placeholder_wraped_rows.push_back(placeholder_translated.substr(line_range.x, line_range.y - line_range.x));
	}
}
void TextEdit::_update_theme_item_cache() {