### 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
return Point2i(-1, -1);
		}
		return Point2i(text[row].length(), row);
	}
	int col = 0;
	int colx = p_pos.x - (theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
	colx += first_visible_col;
	col = _get_char_pos_for_line(colx, row, wrap_index);
	if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE && wrap_index < get_line_wrap_count(row)) {
		
		Vector<String> rows2 = get_line_wrapped_text(row);
		int row_end_col = 0;
		for (int i = 0; i < wrap_index + 1; i++) {
			row_end_col += rows2[i].length();
		}
		if (col >= row_end_col) {
			col -= 1;
		}
	}
	RID text_rid = text.get_line_data(row)->get_line_rid(wrap_index);
	if (is_layout_rtl()) {
		colx = TS->shaped_text_get_size(text_rid).x - colx;
	}
	col = TS->shaped_text_hit_test_position(text_rid, colx);
	if (!caret_mid_grapheme_enabled) {
		col = TS->shaped_text_closest_character_pos(text_rid, col);
	}
	return Point2i(col, row);
}
Point2i TextEdit::get_pos_at_line_column(int p_line, int p_column) const {