Nodes: Reroute becomes active if singular

When using Shift + RMB drag to create a reroute, the newly created
reroute does not become active. If you then rename it will rename the
previously active node.

This PR sets the newly created reroute to be active if only one is
created. If more than one is created the order is not well defined
and also unclear whether it would be first or last to become active.

Pull Request: https://projects.blender.org/blender/blender/pulls/146774
This commit is contained in:
Brady Johnston
2025-09-25 14:47:50 +02:00
committed by Hans Goudey
parent 28b97afda2
commit e869ae360c

View File

@@ -179,7 +179,10 @@ static wmOperatorStatus add_reroute_exec(bContext *C, wmOperator *op)
* Further deduplication using the second map means we only have one cut per link. */
Map<bNodeSocket *, RerouteCutsForSocket> cuts_per_socket;
int intersection_count = 0;
LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) {
if (node_link_is_hidden_or_dimmed(region.v2d, *link)) {
continue;
}
@@ -190,6 +193,7 @@ static wmOperatorStatus add_reroute_exec(bContext *C, wmOperator *op)
RerouteCutsForSocket &from_cuts = cuts_per_socket.lookup_or_add_default(link->fromsock);
from_cuts.from_node = link->fromnode;
from_cuts.links.add(link, *cut);
intersection_count++;
}
for (const auto item : cuts_per_socket.items()) {
@@ -197,6 +201,10 @@ static wmOperatorStatus add_reroute_exec(bContext *C, wmOperator *op)
bNode *reroute = bke::node_add_static_node(C, ntree, NODE_REROUTE);
if (intersection_count == 1) {
bke::node_set_active(ntree, *reroute);
}
bke::node_add_link(ntree,
*item.value.from_node,
*item.key,