### Godot version

v4.1.rc1.official [1f9e540f1]

### System information

Windows 10

### Issue description

Attempting to reorder the children of a TabContainer results in an unintended ordering and incorrect undo states.

Also happens in v4.0.3.stable.official [5222a99f5].

https://github.com/godotengine/godot/assets/3820082/2c2458e3-88ad-46d9-8a04-f289a049984a



### Steps to reproduce

1. Add a new TabContainer
2. Add a few children to it
3. Drag and drop to erroneously reorder them
4. Attempt to undo the change

### Minimal reproduction project

N/A
if (p_type.is_empty() || cptr[i]->is_class(p_type)) {
				ret.append(cptr[i]);
			} else if (cptr[i]->get_script_instance()) {
				Ref<Script> scr = cptr[i]->get_script_instance()->get_script();
				while (scr.is_valid()) {
					if ((ScriptServer::is_global_class(p_type) && ScriptServer::get_global_class_path(p_type) == scr->get_path()) || p_type == scr->get_path()) {
						ret.append(cptr[i]);
						break;
					}
					scr = scr->get_base_script();
				}
			}
		}
		if (p_recursive) {
			ret.append_array(cptr[i]->find_children(p_pattern, p_type, true, p_owned));
		}
	}
	return ret;
}
void Node::reparent(Node *p_parent, bool p_keep_global_transform) {
	ERR_THREAD_GUARD
	ERR_FAIL_NULL(p_parent);
	ERR_FAIL_NULL_MSG(data.parent, "Node needs a parent to be reparented.");
	if (p_parent == data.parent) {
		return;
	}
	data.parent->remove_child(this);
	p_parent->add_child(this);
}
Node *Node::get_parent() const {