From 053caa4ccbab0519181d712d4165daed736eb778 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:14:46 +1000 Subject: [PATCH] Add node disconnect shortcuts (#31) * Fix loop break missing * Fix logic - cannot reconnect AND disconnect * Add ctrl + alt + click to disconnect nodes Adds disconnect feature and very minor bug fixes (in separate commits): - Ctrl + Alt + Click: Disconnect an input or output - Ctrl + Alt + Click & Drag: Rewire any input/output to another node with a single click - Added LiteGraph setting, on by default. 6036: skip_action = true Not sure why skip_action was set to true, here. It prevents disconnect and drag to a new output on the same click, so I've included it in the main commit. Ideally, this should be controlled by a consumer hook, e.g. onDisconnectInput. --- src/litegraph.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/litegraph.js b/src/litegraph.js index 8059750f0..a3e890c6c 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -112,6 +112,7 @@ shift_click_do_break_link_from: false, // [false!] prefer false if results too easy to break links - implement with ALT or TODO custom keys click_do_break_link_to: false, // [false!]prefer false, way too easy to break links + ctrl_alt_click_do_break_link: true, // [true!] who accidentally ctrl-alt-clicks on an in/output? nobody! that's who! search_hide_on_mouse_leave: true, // [false on mobile] better true if not touch device, TODO add an helper/listener to close if false search_filter_enabled: false, // [true!] enable filtering slots type in the search widget, !requires auto_load_slot_types or manual set registered_slot_[in/out]_types and slot_types_[in/out] @@ -5907,7 +5908,7 @@ LGraphNode.prototype.executeAction = function(action) //left button mouse / single finger if (e.which == 1 && !this.pointer_is_double) { - if (e.ctrlKey) + if (e.ctrlKey && !e.altKey) { this.dragging_rectangle = new Float32Array(4); this.dragging_rectangle[0] = e.canvasX; @@ -5918,7 +5919,7 @@ LGraphNode.prototype.executeAction = function(action) } // clone node ALT dragging - if (LiteGraph.alt_drag_do_clone_nodes && e.altKey && node && this.allow_interaction && !skip_action && !this.read_only) + if (LiteGraph.alt_drag_do_clone_nodes && e.altKey && !e.ctrlKey && node && this.allow_interaction && !skip_action && !this.read_only) { const cloned = node.clone() if (cloned) { @@ -5984,6 +5985,10 @@ LGraphNode.prototype.executeAction = function(action) if (e.shiftKey) { node.disconnectOutput(i); } + } else if (LiteGraph.ctrl_alt_click_do_break_link) { + if (e.ctrlKey && e.altKey && !e.shiftKey) { + node.disconnectOutput(i); + } } if (is_double_click) { @@ -6031,15 +6036,9 @@ LGraphNode.prototype.executeAction = function(action) var link_info = this.graph.links[ input.link ]; //before disconnecting - if (LiteGraph.click_do_break_link_to){ + if (LiteGraph.click_do_break_link_to || (LiteGraph.ctrl_alt_click_do_break_link && e.ctrlKey && e.altKey && !e.shiftKey)){ node.disconnectInput(i); - this.dirty_bgcanvas = true; - skip_action = true; - }else{ - // do same action as has not node ? - } - - if ( + } else if ( this.allow_reconnect_links || //this.move_destination_link_without_shift || e.shiftKey @@ -6059,6 +6058,8 @@ LGraphNode.prototype.executeAction = function(action) this.dirty_bgcanvas = true; skip_action = true; + }else{ + // do same action as has not node ? } @@ -6077,6 +6078,8 @@ LGraphNode.prototype.executeAction = function(action) this.dirty_bgcanvas = true; skip_action = true; } + + break; } } }