### 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
Vector<Vector2i> ret;
	ERR_FAIL_INDEX_V(p_line, text.size(), ret);
	for (int i = 0; i < text[p_line].data_buf->get_line_count(); i++) {
		ret.push_back(text[p_line].data_buf->get_line_range(i));
	}
	return ret;
}
const Ref<TextParagraph> TextEdit::Text::get_line_data(int p_line) const {
	ERR_FAIL_INDEX_V(p_line, text.size(), Ref<TextParagraph>());
	return text[p_line].data_buf;
}
_FORCE_INLINE_ const String &TextEdit::Text::operator[](int p_line) const {
	return text[p_line].data;
}
void TextEdit::Text::_calculate_line_height() {
	int height = 0;
	for (const Line &l : text) {
		
		if (l.height == line_height) {
			height = line_height;
			break;
		}
		height = MAX(height, l.height);
	}
	line_height = height;
}
void TextEdit::Text::_calculate_max_line_width() {