### 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 (!tooltip_callback.is_valid()) {
		return Control::get_tooltip(p_pos);
	}
	Point2i pos = get_line_column_at_pos(p_pos);
	int row = pos.y;
	int col = pos.x;
	String s = text[row];
	if (s.length() == 0) {
		return Control::get_tooltip(p_pos);
	}
	int beg, end;
	if (select_word(s, col, beg, end)) {
		Variant args[1] = { s.substr(beg, end - beg) };
		const Variant *argp[] = { &args[0] };
		Callable::CallError ce;
		Variant ret;
		tooltip_callback.callp(argp, 1, ret, ce);
		ERR_FAIL_COND_V_MSG(ce.error != Callable::CallError::CALL_OK, "", "Failed to call custom tooltip.");
		return ret;
	}
	return Control::get_tooltip(p_pos);
}
void TextEdit::set_tooltip_request_func(const Callable &p_tooltip_callback) {