From a4f81c683896b9ed0c7ca8411c7796f7ccfe65f9 Mon Sep 17 00:00:00 2001 From: Fabian Schempp Date: Tue, 2 Mar 2021 23:09:38 +0100 Subject: Fix T85966: Wrong link picked when dragging multi-input socket The socket drag operator stored the index of the last picked socket into RNA in case the mouse cursor leaves the link while dragging. This id was not unique which is why sometimes a link from an other node with the same id is picked. This patch changes the way the last picked link is stored and stores a pointer to the link directly into bNodeLinkDrag struct instead. Differential Revision: https://developer.blender.org/D10590 --- .../editors/space_node/node_relationships.c | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'source/blender/editors/space_node/node_relationships.c') diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index d6edfcce8e8..218102d2261 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -280,7 +280,7 @@ static void pick_input_link_by_link_intersect(const bContext *C, float distance = dist_squared_to_line_segment_v2(cursor, l1, l2); if (distance < cursor_link_touch_distance) { link_to_pick = link; - RNA_int_set(op->ptr, "last_picked_link_index", link->multi_input_socket_index); + nldrag->last_picked_multi_input_socket_link = link_to_pick; } } } @@ -290,13 +290,9 @@ static void pick_input_link_by_link_intersect(const bContext *C, * Not essential for the basic behavior, but can make interaction feel a bit better if * the mouse moves to the right and loses the "selection." */ if (!link_to_pick) { - int last_picked_link_index = RNA_int_get(op->ptr, "last_picked_link_index"); - if (last_picked_link_index > -1) { - LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { - if (link->multi_input_socket_index == last_picked_link_index) { - link_to_pick = link; - } - } + bNodeLink *last_picked_link = nldrag->last_picked_multi_input_socket_link; + if (last_picked_link) { + link_to_pick = last_picked_link; } } @@ -1032,13 +1028,14 @@ static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event) float cursor[2]; UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); RNA_float_set_array(op->ptr, "drag_start", cursor); - RNA_int_set(op->ptr, "last_picked_link_index", -1); RNA_boolean_set(op->ptr, "has_link_picked", false); ED_preview_kill_jobs(CTX_wm_manager(C), bmain); bNodeLinkDrag *nldrag = node_link_init(bmain, snode, cursor, detach); + nldrag->last_picked_multi_input_socket_link = NULL; + if (nldrag) { op->customdata = nldrag; BLI_addtail(&snode->runtime->linkdrag, nldrag); @@ -1102,15 +1099,6 @@ void NODE_OT_link(wmOperatorType *ot) -UI_PRECISION_FLOAT_MAX, UI_PRECISION_FLOAT_MAX); RNA_def_property_flag(prop, PROP_HIDDEN); - RNA_def_int(ot->srna, - "last_picked_link_index", - -1, - -1, - 4095, - "Last Picked Link Index", - "The index of the last picked link on a multi-input socket", - -1, - 4095); RNA_def_property_flag(prop, PROP_HIDDEN); } -- cgit v1.2.3