Skip to content

Commit

Permalink
Fixed duplicating nodes at different depths in SceneTreeDock
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSofox committed Dec 22, 2023
1 parent f8a2a91 commit ed64879
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {

selection.sort_custom<Node::Comparator>();

Node *add_below_node = selection.back()->get();
HashMap<const Node *, Node *> add_below_map;

for (List<Node *>::Element *E = selection.back(); E; E = E->prev()) {
Node *node = E->get();
if (!add_below_map.has(node->get_parent())) {
add_below_map.insert(node->get_parent(), node);
}
}

for (Node *node : selection) {
Node *parent = node->get_parent();
Expand All @@ -740,7 +747,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {

dup->set_name(parent->validate_child_name(dup));

undo_redo->add_do_method(add_below_node, "add_sibling", dup, true);
undo_redo->add_do_method(add_below_map[parent], "add_sibling", dup, true);

for (Node *F : owned) {
if (!duplimap.has(F)) {
Expand All @@ -759,7 +766,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
undo_redo->add_do_method(ed, "live_debug_duplicate_node", edited_scene->get_path_to(node), dup->get_name());
undo_redo->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).path_join(dup->get_name())));

add_below_node = dup;
add_below_map[parent] = dup;
}

undo_redo->commit_action();
Expand Down

0 comments on commit ed64879

Please sign in to comment.