Merge pull request #370 from tianlang0704/master

Add Ctrl+Shift+V to paste with unselected nodes connected
This commit is contained in:
Javi Agenjo
2023-04-10 18:55:35 +02:00
committed by GitHub

View File

@@ -6992,9 +6992,9 @@ LGraphNode.prototype.executeAction = function(action)
} }
} }
if (e.code == "KeyV" && (e.metaKey || e.ctrlKey) && !e.shiftKey) { if (e.code == "KeyV" && (e.metaKey || e.ctrlKey)) {
//paste //paste
this.pasteFromClipboard(); this.pasteFromClipboard(e.shiftKey);
} }
//delete or backspace //delete or backspace
@@ -7079,15 +7079,15 @@ LGraphNode.prototype.executeAction = function(action)
var target_node = this.graph.getNodeById( var target_node = this.graph.getNodeById(
link_info.origin_id link_info.origin_id
); );
if (!target_node || !this.selected_nodes[target_node.id]) { if (!target_node) {
//improve this by allowing connections to non-selected nodes
continue; continue;
} //not selected }
clipboard_info.links.push([ clipboard_info.links.push([
target_node._relative_id, target_node._relative_id,
link_info.origin_slot, //j, link_info.origin_slot, //j,
node._relative_id, node._relative_id,
link_info.target_slot link_info.target_slot,
target_node.id
]); ]);
} }
} }
@@ -7098,7 +7098,7 @@ LGraphNode.prototype.executeAction = function(action)
); );
}; };
LGraphCanvas.prototype.pasteFromClipboard = function() { LGraphCanvas.prototype.pasteFromClipboard = function(isConnectUnselected = false) {
var data = localStorage.getItem("litegrapheditor_clipboard"); var data = localStorage.getItem("litegrapheditor_clipboard");
if (!data) { if (!data) {
return; return;
@@ -7147,7 +7147,16 @@ LGraphNode.prototype.executeAction = function(action)
//create links //create links
for (var i = 0; i < clipboard_info.links.length; ++i) { for (var i = 0; i < clipboard_info.links.length; ++i) {
var link_info = clipboard_info.links[i]; var link_info = clipboard_info.links[i];
var origin_node = nodes[link_info[0]]; var origin_node;
var origin_node_relative_id = link_info[0];
if (origin_node_relative_id != null) {
origin_node = nodes[origin_node_relative_id];
} else if (isConnectUnselected) {
var origin_node_id = link_info[4];
if (origin_node_id) {
origin_node = this.graph.getNodeById(origin_node_id);
}
}
var target_node = nodes[link_info[2]]; var target_node = nodes[link_info[2]];
if( origin_node && target_node ) if( origin_node && target_node )
origin_node.connect(link_info[1], target_node, link_info[3]); origin_node.connect(link_info[1], target_node, link_info[3]);