### 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
_scroll_down(15 * mb->get_factor(), true);
				} else if (v_scroll->is_visible()) {
					
					_scroll_down(3 * mb->get_factor(), true);
				}
			}
			if (mb->get_button_index() == MouseButton::WHEEL_LEFT) {
				h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
			}
			if (mb->get_button_index() == MouseButton::WHEEL_RIGHT) {
				h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor()));
			}
			if (mb->get_button_index() == MouseButton::LEFT) {
				_reset_caret_blink_timer();
				Point2i pos = get_line_column_at_pos(mpos);
				int row = pos.y;
				int col = pos.x;
				int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT);
				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) {
						emit_signal(SNAME("gutter_clicked"), row, i);
						return;
					}
					left_margin += gutters[i].width;
				}
				
				if (draw_minimap) {