### 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_line, text.size(), 0);
	if (p_wrap_index != -1) {
		return text[p_line].data_buf->get_line_width(p_wrap_index);
	}
	return text[p_line].data_buf->get_size().x;
}
int TextEdit::Text::get_line_height() const {
	return line_height;
}
void TextEdit::Text::set_width(float p_width) {
	width = p_width;
}
float TextEdit::Text::get_width() const {
	return width;
}
void TextEdit::Text::set_brk_flags(BitField<TextServer::LineBreakFlag> p_flags) {
	brk_flags = p_flags;
}
BitField<TextServer::LineBreakFlag> TextEdit::Text::get_brk_flags() const {
	return brk_flags;
}
int TextEdit::Text::get_line_wrap_amount(int p_line) const {
	ERR_FAIL_INDEX_V(p_line, text.size(), 0);
	return text[p_line].data_buf->get_line_count() - 1;
}
Vector<Vector2i> TextEdit::Text::get_line_wrap_ranges(int p_line) const {