### 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
}
						}
					}
				}
			}
			bool draw_placeholder = text.size() == 1 && text[0].is_empty() && ime_text.is_empty();
			
			String highlighted_text = get_selected_text(0);
			
			bool only_whitespaces_highlighted = highlighted_text.strip_edges().is_empty();
			HashMap<int, HashSet<int>> caret_line_wrap_index_map;
			Vector<int> carets_wrap_index;
			carets_wrap_index.resize(carets.size());
			for (int i = 0; i < carets.size(); i++) {
				carets.write[i].visible = false;
				int wrap_index = get_caret_wrap_index(i);
				caret_line_wrap_index_map[get_caret_line(i)].insert(wrap_index);
				carets_wrap_index.write[i] = wrap_index;
			}
			int first_vis_line = get_first_visible_line() - 1;
			int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0);
			draw_amount += draw_placeholder ? placeholder_wraped_rows.size() - 1 : get_line_wrap_count(first_vis_line + 1);
			
			if (draw_minimap) {
				int minimap_visible_lines = get_minimap_visible_lines();
				int minimap_line_height = (minimap_char_size.y + minimap_line_spacing);
				int minimap_tab_size = minimap_char_size.x * text.get_tab_size();
				
				int viewport_height = (draw_amount - 1) * minimap_line_height;
				int control_height = _get_control_height() - viewport_height;