From f35dd34da99eaaa680e2691f7a5d2f37728c16f5 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 9 Jan 2016 00:29:04 +0000 Subject: [PATCH] Allow shift-click to detach existing wires --- editor/js/ui/view.js | 193 ++++++++++++++++++++++++++++++------------- 1 file changed, 135 insertions(+), 58 deletions(-) diff --git a/editor/js/ui/view.js b/editor/js/ui/view.js index 30b24142a..1f83a5cd7 100644 --- a/editor/js/ui/view.js +++ b/editor/js/ui/view.js @@ -231,7 +231,21 @@ RED.view = (function() { }); grid.style("visibility","hidden"); - var drag_line = vis.append("svg:path").attr("class", "drag_line"); + var dragGroup = vis.append('g'); + var drag_lines = []; + + function showDragLines(nodes) { + for (var i=0;i0)?0.5:-0.5)*(((3*node_height)-Math.abs(dy))/(3*node_height))*(Math.min(node_width,Math.abs(dx))/(node_width)) ; + if (drag_lines.length === 0) { + if (d3.event.shiftKey) { + // Get all the wires we need to detach. + var links = []; + var filter; + if (mousedown_port_type === 0) { + filter = { + source:mousedown_node, + sourcePort: mousedown_port_index + } + } else { + filter = { + target: mousedown_node + } + } + var existingLinks = RED.nodes.filterLinks(filter); + for (var i=0;i0)?0.5:-0.5)*(((3*node_height)-Math.abs(dy))/(3*node_height))*(Math.min(node_width,Math.abs(dx))/(node_width)) ; + } + } + + drag_line.el.attr("d", + "M "+(drag_line.node.x+sc*drag_line.node.w/2)+" "+(drag_line.node.y+portY)+ + " C "+(drag_line.node.x+sc*(drag_line.node.w/2+node_width*scale))+" "+(drag_line.node.y+portY+scaleY*node_height)+" "+ + (mousePos[0]-sc*(scale)*node_width)+" "+(mousePos[1]-scaleY*node_height)+" "+ + mousePos[0]+" "+mousePos[1] + ); + } d3.event.preventDefault(); } else if (mouse_mode == RED.state.MOVING) { mousePos = d3.mouse(document.body); @@ -587,7 +638,19 @@ RED.view = (function() { function canvasMouseUp() { if (mousedown_node && mouse_mode == RED.state.JOINING) { - drag_line.attr("class", "drag_line_hidden"); + var removedLinks = []; + for (var i=0;i 0) { if (typeof TouchEvent != "undefined" && d3.event instanceof TouchEvent) { RED.nodes.eachNode(function(n) { - if (n.z == RED.workspaces.active()) { - var hw = n.w/2; - var hh = n.h/2; - if (n.x-hw mouse_position[0] && - n.y-hhmouse_position[1]) { - mouseup_node = n; - portType = mouseup_node.inputs>0?1:0; - portIndex = 0; - } + if (n.z == RED.workspaces.active()) { + var hw = n.w/2; + var hh = n.h/2; + if (n.x-hw mouse_position[0] && + n.y-hhmouse_position[1]) { + mouseup_node = n; + portType = mouseup_node.inputs>0?1:0; + portIndex = 0; } + } }); } else { mouseup_node = d; } - if (portType == mousedown_port_type || mouseup_node === mousedown_node) { - drag_line.attr("class", "drag_line_hidden"); - resetMouseVars(); - return; + var addedLinks = []; + var removedLinks = []; + + for (i=0;i 0 || removedLinks.length > 0) { var historyEvent = { t:'add', - links:[link], + links:addedLinks, + removedLinks: removedLinks, dirty:RED.nodes.dirty() }; if (activeSubflow) { @@ -980,8 +1056,9 @@ RED.view = (function() { RED.history.push(historyEvent); updateActiveNodes(); RED.nodes.dirty(true); - } else { } + resetMouseVars(); + hideDragLines(); selected_link = null; redraw(); }