### 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
if (placeholder_text == p_text) {
		return;
	}
	placeholder_text = p_text;
	_update_placeholder();
	queue_redraw();
}
String TextEdit::get_placeholder() const {
	return placeholder_text;
}
void TextEdit::set_line(int p_line, const String &p_new_text) {
	if (p_line < 0 || p_line >= text.size()) {
		return;
	}
	begin_complex_operation();
	_remove_text(p_line, 0, p_line, text[p_line].length());
	_insert_text(p_line, 0, p_new_text);
	for (int i = 0; i < carets.size(); i++) {
		if (get_caret_line(i) == p_line && get_caret_column(i) > p_new_text.length()) {
			set_caret_column(p_new_text.length(), false, i);
		}
		if (has_selection(i) && p_line == get_selection_to_line(i) && get_selection_to_column(i) > text[p_line].length()) {
			carets.write[i].selection.to_column = text[p_line].length();
		}
	}
	end_complex_operation();
}
String TextEdit::get_line(int p_line) const {