### 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
ERR_FAIL_INDEX_V(p_caret, carets.size(), 0);
	return carets[p_caret].line;
}
void TextEdit::set_caret_column(int p_col, bool p_adjust_viewport, int p_caret) {
	ERR_FAIL_INDEX(p_caret, carets.size());
	if (p_col < 0) {
		p_col = 0;
	}
	if (p_col > get_line(get_caret_line(p_caret)).length()) {
		p_col = get_line(get_caret_line(p_caret)).length();
	}
	bool caret_moved = get_caret_column(p_caret) != p_col;
	carets.write[p_caret].column = p_col;
	carets.write[p_caret].last_fit_x = _get_column_x_offset_for_line(get_caret_column(p_caret), get_caret_line(p_caret), get_caret_column(p_caret));
	if (is_inside_tree() && p_adjust_viewport) {
		adjust_viewport_to_caret(p_caret);
	}
	if (caret_moved && !caret_pos_dirty) {
		if (is_inside_tree()) {
			MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
		}
		caret_pos_dirty = true;
	}
}
int TextEdit::get_caret_column(int p_caret) const {