diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-15 13:25:30 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-15 13:25:30 +0100 |
commit | 91fcc3986eca5331b4cc44a67adcc2f29a49eb66 (patch) | |
tree | 8019a84ea60ee4f4f068b2aab4ff4be01fcb5fd0 | |
parent | 2444860d037f3b43eb958fd650b2ed731eaea5f3 (diff) | |
parent | 6b2febe7941c5b02a179f408df414639413e9a26 (diff) |
Merge pull request #68340 from KoBeWi/deparent
Don't reparent dragged node when non needed
-rw-r--r-- | editor/scene_tree_dock.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 64ac38aaa5..a7124c130b 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1814,7 +1814,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V // Sort by tree order, so re-adding is easy. p_nodes.sort_custom<Node::Comparator>(); - editor_data->get_undo_redo()->create_action(TTR("Reparent Node")); + editor_data->get_undo_redo()->create_action(TTR("Reparent Node"), UndoRedo::MERGE_DISABLE, p_nodes[0]); HashMap<Node *, NodePath> path_renames; Vector<StringName> former_names; @@ -1835,14 +1835,17 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V owners.push_back(E); } - if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) { + bool same_parent = new_parent == node->get_parent(); + if (same_parent && node->get_index() < p_position_in_parent + ni) { inc--; // If the child will generate a gap when moved, adjust. } - editor_data->get_undo_redo()->add_do_method(node->get_parent(), "remove_child", node); - editor_data->get_undo_redo()->add_do_method(new_parent, "add_child", node, true); + if (!same_parent) { + editor_data->get_undo_redo()->add_do_method(node->get_parent(), "remove_child", node); + editor_data->get_undo_redo()->add_do_method(new_parent, "add_child", node, true); + } - if (p_position_in_parent >= 0) { + if (p_position_in_parent >= 0 || same_parent) { editor_data->get_undo_redo()->add_do_method(new_parent, "move_child", node, p_position_in_parent + inc); } |