### 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
default: {
						break;
					}
				}
			}
		}
		
		Vector2i current_hovered_gutter = Vector2i(-1, -1);
		int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT);
		if (mpos.x <= left_margin + gutters_width + gutter_padding) {
			int hovered_row = get_line_column_at_pos(mpos).y;
			for (int i = 0; i < gutters.size(); i++) {
				if (!gutters[i].draw || gutters[i].width <= 0) {
					continue;
				}
				if (mpos.x >= left_margin && mpos.x < left_margin + gutters[i].width) {
					
					current_hovered_gutter = Vector2i(i, hovered_row);
					break;
				}
				left_margin += gutters[i].width;
			}
		}
		if (current_hovered_gutter != hovered_gutter) {
			hovered_gutter = current_hovered_gutter;
			queue_redraw();
		}
		if (drag_action && can_drop_data(mpos, get_viewport()->gui_get_drag_data())) {
			drag_caret_force_displayed = true;
			Point2i pos = get_line_column_at_pos(get_local_mouse_pos());