### 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
while (_is_line_hidden(minimap_line)) {
						minimap_line++;
						if (minimap_line < 0 || minimap_line >= (int)text.size()) {
							break;
						}
					}
					if (minimap_line < 0 || minimap_line >= (int)text.size()) {
						break;
					}
					Dictionary color_map = _get_line_syntax_highlighting(minimap_line);
					Color line_background_color = text.get_line_background_color(minimap_line);
					if (line_background_color != theme_cache.background_color) {
						
						line_background_color.a = 1.0;
					} else {
						line_background_color.a *= 0.6;
					}
					Color current_color = theme_cache.font_color;
					if (!editable) {
						current_color = theme_cache.font_readonly_color;
					}
					Vector<String> wrap_rows = get_line_wrapped_text(minimap_line);
					int line_wrap_amount = get_line_wrap_count(minimap_line);
					int last_wrap_column = 0;
					for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
						if (line_wrap_index != 0) {
							i++;
							if (i >= minimap_draw_amount) {
								break;
							}