Fix #108049: De-duplicate copied active node #108082

Closed
Iliya Katushenock wants to merge 6 commits from mod_moder:tmp_fix_deduplicate_active_node_of_copys into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 16 additions and 0 deletions

View File

@ -42,6 +42,7 @@ struct NodeClipboardItem {
};
struct NodeClipboard {
bNode *active_node = nullptr;
Vector<NodeClipboardItem> nodes;
Vector<bNodeLink> links;
@ -52,6 +53,7 @@ struct NodeClipboard {
}
this->nodes.clear_and_shrink();
this->links.clear_and_shrink();
this->active_node = nullptr;
}
/**
@ -135,6 +137,10 @@ static int node_clipboard_copy_exec(bContext *C, wmOperator * /*op*/)
}
}
if (bNode *active_node = nodeGetActive(&tree)) {
clipboard.active_node = node_map.lookup_default(active_node, nullptr);
}
for (bNode *new_node : node_map.values()) {
/* Parent pointer must be redirected to new node or detached if parent is not copied. */
if (new_node->parent) {
@ -326,6 +332,10 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
update_multi_input_indices_for_removed_links(*new_node);
}
if (bNode *new_active_node = node_map.lookup_default(clipboard.active_node, nullptr)) {
nodeSetActive(&tree, new_active_node);
}
Main *bmain = CTX_data_main(C);
ED_node_tree_propagate_change(C, bmain, &tree);
/* Pasting nodes can create arbitrary new relations because nodes can reference IDs. */

View File

@ -1295,6 +1295,8 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
Map<const bNodeSocket *, bNodeSocket *> socket_map;
Map<const ID *, ID *> duplicated_node_groups;
bNode *active_node = nodeGetActive(ntree);
mod_moder marked this conversation as resolved
Review

typo: actibe

typo: acti**b**e
for (bNode *node : get_selected_nodes(*ntree)) {
bNode *new_node = bke::node_copy_with_mapping(
ntree, *node, LIB_ID_COPY_DEFAULT, true, socket_map);
@ -1370,6 +1372,10 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
remap_pairing(*ntree, node_map);
if (bNode *new_active_node = node_map.lookup_default(active_node, nullptr)) {
nodeSetActive(ntree, new_active_node);
}
/* Deselect old nodes, select the copies instead. */
for (const auto item : node_map.items()) {
bNode *src_node = item.key;