Fix #138265: Ctrl+shift+left click to Preview socket inconsistency

There are two implementations:

- "Link to Viewer Node"
-- when clicking on a socket directly, link from that socket [done by
first selecting and then taking that selection state into account]
-- otherwise cycles through available sockets
- "Connect to Output" [python operator, made core from Node Wrangler]
-- does not take socket selection into account
-- only cycles through available sockets

So goal is to replicate behavior of "Link to Viewer Node" in "Connect to
Output" in terms of "which socket to link from"

This is done by
- exposing a sockets select state to python
- tweaking the call to bpy.ops.node.select so it does socket selection
as well
- take that selection into account

Pull Request: https://projects.blender.org/blender/blender/pulls/138323
This commit is contained in:
Philipp Oeser
2025-05-11 09:52:16 +02:00
committed by Philipp Oeser
parent e51b4d5aa7
commit 9077a26ba2
2 changed files with 15 additions and 1 deletions

View File

@@ -192,6 +192,8 @@ class NODE_OT_connect_to_output(Operator, NodeEditorBase):
out_i = None
valid_outputs = []
for i, out in enumerate(node.outputs):
if out.select:
return i
if is_visible_socket(out) and (not check_type or out.type == socket_type):
valid_outputs.append(i)
if valid_outputs:
@@ -259,7 +261,7 @@ class NODE_OT_connect_to_output(Operator, NodeEditorBase):
mlocx = event.mouse_region_x
mlocy = event.mouse_region_y
select_node = bpy.ops.node.select(location=(mlocx, mlocy), extend=False)
select_node = bpy.ops.node.select(location=(mlocx, mlocy), extend=False, socket_select=True)
if 'FINISHED' not in select_node: # only run if mouse click is on a node.
return {'CANCELLED'}

View File

@@ -370,6 +370,13 @@ static bool rna_NodeSocket_is_output_get(PointerRNA *ptr)
return sock->in_out == SOCK_OUT;
}
static bool rna_NodeSocket_select_get(PointerRNA *ptr)
{
const bNodeSocket *socket = ptr->data_as<bNodeSocket>();
return (socket->flag & SELECT) != 0;
}
static int rna_NodeSocket_link_limit_get(PointerRNA *ptr)
{
bNodeSocket *sock = static_cast<bNodeSocket *>(ptr->data);
@@ -673,6 +680,11 @@ static void rna_def_node_socket(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Is Output", "True if the socket is an output, otherwise input");
prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_NodeSocket_select_get", nullptr);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Select", "True if the socket is selected");
prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "flag", SOCK_HIDDEN);
RNA_def_property_boolean_funcs(prop, nullptr, "rna_NodeSocket_hide_set");