### 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 selecting_mode;
}
void TextEdit::select_all() {
	if (!selecting_enabled) {
		return;
	}
	if (text.size() == 1 && text[0].length() == 0) {
		return;
	}
	remove_secondary_carets();
	select(0, 0, text.size() - 1, text[text.size() - 1].length());
	set_selection_mode(SelectionMode::SELECTION_MODE_SHIFT, 0, 0);
	carets.write[0].selection.shiftclick_left = true;
	set_caret_line(get_selection_to_line(), false);
	set_caret_column(get_selection_to_column(), false);
	queue_redraw();
}
void TextEdit::select_word_under_caret(int p_caret) {
	ERR_FAIL_COND(p_caret > carets.size());
	if (!selecting_enabled) {
		return;
	}
	if (text.size() == 1 && text[0].length() == 0) {
		return;
	}
	for (int c = 0; c < carets.size(); c++) {
		if (p_caret != -1 && p_caret != c) {