### 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 (p_from_line == p_to_line) {
		return;
	}
	bool dirty_height = false;
	bool dirty_width = false;
	for (int i = p_from_line; i < p_to_line; i++) {
		if (!dirty_height && text[i].height == line_height) {
			dirty_height = true;
		}
		if (!dirty_width && text[i].width == max_width) {
			dirty_width = true;
		}
		if (dirty_height && dirty_width) {
			break;
		}
	}
	int diff = (p_to_line - p_from_line);
	for (int i = p_to_line; i < text.size() - 1; i++) {
		text.write[(i - diff) + 1] = text[i + 1];
	}
	text.resize(text.size() - diff);
	if (dirty_height) {
		_calculate_line_height();
	}
	if (dirty_width) {
		_calculate_max_line_width();
	}
}
void TextEdit::Text::add_gutter(int p_at) {