Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating any useless undo action when dragging nodes in place #80817

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,8 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V

p_nodes.sort_custom<Node::Comparator>(); //Makes result reliable.

const int first_idx = p_position_in_parent == -1 ? p_new_parent->get_child_count(false) : p_position_in_parent;
int nodes_before = first_idx;
bool no_change = true;
for (int ni = 0; ni < p_nodes.size(); ni++) {
if (p_nodes[ni] == p_new_parent) {
Expand All @@ -1919,7 +1921,17 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
// `move_child` + `get_index` doesn't really work for internal nodes.
ERR_FAIL_COND_MSG(p_nodes[ni]->get_internal_mode() != INTERNAL_MODE_DISABLED, "Trying to move internal node, this is not supported.");

if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index(false)) {
if (p_nodes[ni]->get_index(false) < first_idx) {
nodes_before--;
}

if (p_nodes[ni]->get_parent() != p_new_parent) {
no_change = false;
}
}

for (int ni = 0; ni < p_nodes.size() && no_change; ni++) {
if (p_nodes[ni]->get_index(false) != nodes_before + ni) {
no_change = false;
}
}
Expand Down
Loading