### 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
}
						}
						char_ofs = 0;
					}
					for (int j = 0; j < gl_size; j++) {
						int64_t color_start = -1;
						for (const Variant *key = color_map.next(nullptr); key; key = color_map.next(key)) {
							if (int64_t(*key) <= glyphs[j].start) {
								color_start = *key;
							} else {
								break;
							}
						}
						const Variant *color_data = (color_start >= 0) ? color_map.getptr(color_start) : nullptr;
						if (color_data != nullptr) {
							current_color = (color_data->operator Dictionary()).get("color", theme_cache.font_color);
							if (!editable && current_color.a > theme_cache.font_readonly_color.a) {
								current_color.a = theme_cache.font_readonly_color.a;
							}
						}
						Color gl_color = current_color;
						for (int c = 0; c < carets.size(); c++) {
							if (has_selection(c) && line >= get_selection_from_line(c) && line <= get_selection_to_line(c)) { 
								int sel_from = (line > get_selection_from_line(c)) ? TS->shaped_text_get_range(rid).x : get_selection_from_column(c);
								int sel_to = (line < get_selection_to_line(c)) ? TS->shaped_text_get_range(rid).y : get_selection_to_column(c);
								if (glyphs[j].start >= sel_from && glyphs[j].end <= sel_to && use_selected_font_color) {
									gl_color = theme_cache.font_selected_color;
								}
							}
						}