Fix: Nodes: restore active node after copy-pasting nodes
This remembers which node was active when copying nodes. When pasting, the node that was active when copied is made active again. Pull Request: https://projects.blender.org/blender/blender/pulls/143832
This commit is contained in:
@@ -61,6 +61,9 @@ struct NodeClipboardItem {
|
||||
ID *id;
|
||||
std::string id_name;
|
||||
std::string library_name;
|
||||
|
||||
/** Remember the active status so that it can be made active again after pasting. */
|
||||
bool was_active = false;
|
||||
};
|
||||
|
||||
struct ClipboardLink {
|
||||
@@ -269,6 +272,7 @@ struct NodeClipboard {
|
||||
NodeClipboardItem item;
|
||||
item.draw_rect = node.runtime->draw_bounds;
|
||||
item.node = new_node;
|
||||
item.was_active = node.flag & NODE_ACTIVE;
|
||||
this->nodes.append(std::move(item));
|
||||
}
|
||||
};
|
||||
@@ -376,6 +380,8 @@ static wmOperatorStatus node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
||||
Map<const bNode *, bNode *> node_map;
|
||||
Map<const bNodeSocket *, bNodeSocket *> socket_map;
|
||||
|
||||
bNode *new_active_node = nullptr;
|
||||
|
||||
/* copy valid nodes from clipboard */
|
||||
for (NodeClipboardItem &item : clipboard.nodes) {
|
||||
const bNode &node = *item.node;
|
||||
@@ -407,6 +413,9 @@ static wmOperatorStatus node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
||||
new_node->typeinfo->poll_instance(new_node, &tree, &disabled_hint))
|
||||
{
|
||||
node_map.add_new(&node, new_node);
|
||||
if (item.was_active) {
|
||||
new_active_node = new_node;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (disabled_hint) {
|
||||
@@ -441,6 +450,10 @@ static wmOperatorStatus node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
}
|
||||
|
||||
if (new_active_node) {
|
||||
bke::node_set_active(tree, *new_active_node);
|
||||
}
|
||||
|
||||
PropertyRNA *offset_prop = RNA_struct_find_property(op->ptr, "offset");
|
||||
if (RNA_property_is_set(op->ptr, offset_prop)) {
|
||||
float2 center(0);
|
||||
|
||||
Reference in New Issue
Block a user