From c2460e2c4efa6c156c25aac1094ff9b5244cbf82 Mon Sep 17 00:00:00 2001 From: CMonk Date: Tue, 11 Apr 2023 01:12:09 +0800 Subject: [PATCH 1/3] Add ctrl+shift+v global switch --- editor/js/defaults.js | 3 ++- editor/js/defaults_mobile.js | 3 ++- src/litegraph.js | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/editor/js/defaults.js b/editor/js/defaults.js index 210ba6354..f51256d83 100644 --- a/editor/js/defaults.js +++ b/editor/js/defaults.js @@ -28,4 +28,5 @@ LiteGraph.do_add_triggers_slots = true; // [true!] will create and connect event LiteGraph.allow_multi_output_for_events = false; // [false!] being events; it is strongly reccomended to use them sequentially; one by one LiteGraph.middle_click_slot_add_default_node = true; //[true!] allows to create and connect a ndoe clicking with the third button (wheel) LiteGraph.release_link_on_empty_shows_menu = true; //[true!] dragging a link to empty space will open a menu, add from list, search or defaults -LiteGraph.pointerevents_method = "mouse"; // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now) \ No newline at end of file +LiteGraph.pointerevents_method = "mouse"; // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now) +LiteGraph.ctrl_shift_v_paste_connect_unselected_outputs = true; //[true!] allows ctrl + shift + v to paste nodes with the outputs of the unselected nodes connected with the inputs of the newly pasted nodes \ No newline at end of file diff --git a/editor/js/defaults_mobile.js b/editor/js/defaults_mobile.js index 630646bd1..04383b1c5 100644 --- a/editor/js/defaults_mobile.js +++ b/editor/js/defaults_mobile.js @@ -28,4 +28,5 @@ LiteGraph.do_add_triggers_slots = true; // [true!] will create and connect event LiteGraph.allow_multi_output_for_events = false; // [false!] being events; it is strongly reccomended to use them sequentially; one by one LiteGraph.middle_click_slot_add_default_node = true; //[true!] allows to create and connect a ndoe clicking with the third button (wheel) LiteGraph.release_link_on_empty_shows_menu = true; //[true!] dragging a link to empty space will open a menu, add from list, search or defaults -LiteGraph.pointerevents_method = "pointer"; // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now) \ No newline at end of file +LiteGraph.pointerevents_method = "pointer"; // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now) +LiteGraph.ctrl_shift_v_paste_connect_unselected_outputs = true; //[true!] allows ctrl + shift + v to paste nodes with the outputs of the unselected nodes connected with the inputs of the newly pasted nodes \ No newline at end of file diff --git a/src/litegraph.js b/src/litegraph.js index 34d4fff7d..c8709abfd 100644 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -140,6 +140,8 @@ pointerevents_method: "mouse", // "mouse"|"pointer" use mouse for retrocompatibility issues? (none found @ now) // TODO implement pointercancel, gotpointercapture, lostpointercapture, (pointerover, pointerout if necessary) + ctrl_shift_v_paste_connect_unselected_outputs: false, //[true!] allows ctrl + shift + v to paste nodes with the outputs of the unselected nodes connected with the inputs of the newly pasted nodes + /** * Register a node class so it can be listed when the user wants to create a new one * @method registerNodeType @@ -7115,6 +7117,10 @@ LGraphNode.prototype.executeAction = function(action) }; LGraphCanvas.prototype.pasteFromClipboard = function(isConnectUnselected = false) { + // if ctrl + shift + v is off, return when isConnectUnselected is true (shift is pressed) to maintain old behavior + if (!LiteGraph.ctrl_shift_v_paste_connect_unselected_outputs && isConnectUnselected) { + return; + } var data = localStorage.getItem("litegrapheditor_clipboard"); if (!data) { return; @@ -7167,7 +7173,7 @@ LGraphNode.prototype.executeAction = function(action) var origin_node_relative_id = link_info[0]; if (origin_node_relative_id != null) { origin_node = nodes[origin_node_relative_id]; - } else if (isConnectUnselected) { + } else if (LiteGraph.ctrl_shift_v_paste_connect_unselected_outputs && isConnectUnselected) { var origin_node_id = link_info[4]; if (origin_node_id) { origin_node = this.graph.getNodeById(origin_node_id); From cf5f917bdcb3e3a485335921ef811d501a91092e Mon Sep 17 00:00:00 2001 From: CMonk Date: Tue, 11 Apr 2023 01:15:10 +0800 Subject: [PATCH 2/3] Add example and simple manual test for copy paste --- editor/examples/copypaste.json | 1 + editor/js/code.js | 7 ++- editor/js/demos.js | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 editor/examples/copypaste.json diff --git a/editor/examples/copypaste.json b/editor/examples/copypaste.json new file mode 100644 index 000000000..086476e89 --- /dev/null +++ b/editor/examples/copypaste.json @@ -0,0 +1 @@ +{"last_node_id":62,"last_link_id":157,"nodes":[{"id":35,"type":"widget/number","pos":[354.0977802999988,-703.6940983999988],"size":[80,60],"flags":{},"order":0,"mode":0,"outputs":[{"name":"","type":"number","links":[32,52,72,94,115,138]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":36,"type":"widget/number","pos":[356.0977802999989,-596.6940983999991],"size":[80,60],"flags":{},"order":1,"mode":0,"outputs":[{"name":"","type":"number","links":[33,53,73,95,116,139]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":37,"type":"widget/number","pos":[359.0977802999989,-495.69409839999975],"size":[80,60],"flags":{},"order":2,"mode":0,"outputs":[{"name":"","type":"number","links":[34,54,74,96,117,140]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":38,"type":"widget/number","pos":[361.0977802999988,-385.69409839999867],"size":[80,60],"flags":{},"order":3,"mode":0,"outputs":[{"name":"","type":"number","links":[35,55,75,97,118,141]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":39,"type":"widget/number","pos":[363.0977802999988,-269.6940983999987],"size":[80,60],"flags":{},"order":4,"mode":0,"outputs":[{"name":"","type":"number","links":[36,56,76,98,119,142]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":40,"type":"widget/number","pos":[366.3589802999999,-157.40999840000026],"size":[80,60],"flags":{},"order":5,"mode":0,"outputs":[{"name":"","type":"number","links":[37,57,77,99,120,143]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":41,"type":"widget/number","pos":[367.3589802999999,-49.40999839999942],"size":[80,60],"flags":{},"order":6,"mode":0,"outputs":[{"name":"","type":"number","links":[38,58,78,100,121,144]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":42,"type":"widget/number","pos":[366.3589802999999,53.59000160000091],"size":[80,60],"flags":{},"order":7,"mode":0,"outputs":[{"name":"","type":"number","links":[39,59,79,101,122,145]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":43,"type":"widget/number","pos":[366.3589802999999,157.59000160000005],"size":[80,60],"flags":{},"order":8,"mode":0,"outputs":[{"name":"","type":"number","links":[40,60,80,102,123,146]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":45,"type":"widget/number","pos":[374,367.58986919999944],"size":[80,60],"flags":{},"order":9,"mode":0,"outputs":[{"name":"","type":"number","links":[42,62,82,104,125,148]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":46,"type":"widget/number","pos":[375,464.58986920000046],"size":[80,60],"flags":{},"order":10,"mode":0,"outputs":[{"name":"","type":"number","links":[43,63,83,105,126,149]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":47,"type":"widget/number","pos":[377,564.5898692000013],"size":[80,60],"flags":{},"order":11,"mode":0,"outputs":[{"name":"","type":"number","links":[44,64,84,106,127,150]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":48,"type":"widget/number","pos":[380,661.5898692000013],"size":[80,60],"flags":{},"order":12,"mode":0,"outputs":[{"name":"","type":"number","links":[45,65,85,107,128,151]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":44,"type":"widget/number","pos":[372,264],"size":[80,60],"flags":{},"order":13,"mode":0,"outputs":[{"name":"","type":"number","links":[41,61,81,103,124,147]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":49,"type":"widget/number","pos":[383,768],"size":[80,60],"flags":{},"order":14,"mode":0,"outputs":[{"name":"","type":"number","links":[46,66,86,108,129,152]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":50,"type":"widget/number","pos":[386,871],"size":[80,60],"flags":{},"order":15,"mode":0,"outputs":[{"name":"","type":"number","links":[47,67,87,109,130,153]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":51,"type":"widget/number","pos":[390,976],"size":[80,60],"flags":{},"order":16,"mode":0,"outputs":[{"name":"","type":"number","links":[48,68,88,110,131,154]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":52,"type":"widget/number","pos":[396,1079],"size":[80,60],"flags":{},"order":17,"mode":0,"outputs":[{"name":"","type":"number","links":[49,89,111]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":55,"type":"features/largeinput_editor","pos":[814.2834913867189,1257.9045020637213],"size":[200,410],"flags":{},"order":28,"mode":0,"inputs":[{"name":"in 1","type":"number","link":71,"slot_index":0},{"name":"in 2","type":"number","link":72,"slot_index":1},{"name":"in 3","type":"number","link":73,"slot_index":2},{"name":"in 4","type":"number","link":74,"slot_index":3},{"name":"in 5","type":"number","link":75,"slot_index":4},{"name":"in 6","type":"number","link":76,"slot_index":5},{"name":"in 7","type":"number","link":77,"slot_index":6},{"name":"in 8","type":"number","link":78,"slot_index":7},{"name":"in 9","type":"number","link":79,"slot_index":8},{"name":"in 10","type":"number","link":80,"slot_index":9},{"name":"in 11","type":"number","link":81,"slot_index":10},{"name":"in 12","type":"number","link":82,"slot_index":11},{"name":"in 13","type":"number","link":83,"slot_index":12},{"name":"in 14","type":"number","link":84,"slot_index":13},{"name":"in 15","type":"number","link":85,"slot_index":14},{"name":"in 16","type":"number","link":86,"slot_index":15},{"name":"in 17","type":"number","link":87,"slot_index":16},{"name":"in 18","type":"number","link":88,"slot_index":17},{"name":"in 19","type":"number","link":89,"slot_index":18},{"name":"in 20","type":"number","link":91,"slot_index":19}],"properties":{}},{"id":54,"type":"features/largeinput_editor","pos":[816.2834913867189,800.9045020637204],"size":[200,410],"flags":{},"order":27,"mode":0,"inputs":[{"name":"in 1","type":"number","link":51,"slot_index":0},{"name":"in 2","type":"number","link":52,"slot_index":1},{"name":"in 3","type":"number","link":53,"slot_index":2},{"name":"in 4","type":"number","link":54,"slot_index":3},{"name":"in 5","type":"number","link":55,"slot_index":4},{"name":"in 6","type":"number","link":56,"slot_index":5},{"name":"in 7","type":"number","link":57,"slot_index":6},{"name":"in 8","type":"number","link":58,"slot_index":7},{"name":"in 9","type":"number","link":59,"slot_index":8},{"name":"in 10","type":"number","link":60,"slot_index":9},{"name":"in 11","type":"number","link":61,"slot_index":10},{"name":"in 12","type":"number","link":62,"slot_index":11},{"name":"in 13","type":"number","link":63,"slot_index":12},{"name":"in 14","type":"number","link":64,"slot_index":13},{"name":"in 15","type":"number","link":65,"slot_index":14},{"name":"in 16","type":"number","link":66,"slot_index":15},{"name":"in 17","type":"number","link":67,"slot_index":16},{"name":"in 18","type":"number","link":68,"slot_index":17},{"name":"in 19","type":"number","link":92,"slot_index":18},{"name":"in 20","type":"number","link":70,"slot_index":19}],"properties":{}},{"id":33,"type":"features/largeinput_editor","pos":[818.2834913867189,334.90450206372003],"size":[200,410],"flags":{},"order":26,"mode":0,"inputs":[{"name":"in 1","type":"number","link":31,"slot_index":0},{"name":"in 2","type":"number","link":32,"slot_index":1},{"name":"in 3","type":"number","link":33,"slot_index":2},{"name":"in 4","type":"number","link":34,"slot_index":3},{"name":"in 5","type":"number","link":35,"slot_index":4},{"name":"in 6","type":"number","link":36,"slot_index":5},{"name":"in 7","type":"number","link":37,"slot_index":6},{"name":"in 8","type":"number","link":38,"slot_index":7},{"name":"in 9","type":"number","link":39,"slot_index":8},{"name":"in 10","type":"number","link":40,"slot_index":9},{"name":"in 11","type":"number","link":41,"slot_index":10},{"name":"in 12","type":"number","link":42,"slot_index":11},{"name":"in 13","type":"number","link":43,"slot_index":12},{"name":"in 14","type":"number","link":44,"slot_index":13},{"name":"in 15","type":"number","link":45,"slot_index":14},{"name":"in 16","type":"number","link":46,"slot_index":15},{"name":"in 17","type":"number","link":47,"slot_index":16},{"name":"in 18","type":"number","link":48,"slot_index":17},{"name":"in 19","type":"number","link":49,"slot_index":18},{"name":"in 20","type":"number","link":50,"slot_index":19}],"properties":{}},{"id":53,"type":"widget/number","pos":[399,1182],"size":[80,60],"flags":{},"order":18,"mode":0,"outputs":[{"name":"","type":"number","links":[50,70,112,135],"slot_index":0}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":57,"type":"widget/number","pos":[405,1443],"size":[80,60],"flags":{},"order":19,"mode":0,"outputs":[{"name":"","type":"number","links":[92,136,155],"slot_index":0}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":61,"type":"features/largeinput_editor","pos":[1070.283491386718,1265.9045020637213],"size":[200,410],"flags":{},"order":25,"mode":0,"inputs":[{"name":"in 1","type":"number","link":137,"slot_index":0},{"name":"in 2","type":"number","link":138,"slot_index":1},{"name":"in 3","type":"number","link":139,"slot_index":2},{"name":"in 4","type":"number","link":140,"slot_index":3},{"name":"in 5","type":"number","link":141,"slot_index":4},{"name":"in 6","type":"number","link":142,"slot_index":5},{"name":"in 7","type":"number","link":143,"slot_index":6},{"name":"in 8","type":"number","link":144,"slot_index":7},{"name":"in 9","type":"number","link":145,"slot_index":8},{"name":"in 10","type":"number","link":146,"slot_index":9},{"name":"in 11","type":"number","link":147,"slot_index":10},{"name":"in 12","type":"number","link":148,"slot_index":11},{"name":"in 13","type":"number","link":149,"slot_index":12},{"name":"in 14","type":"number","link":150,"slot_index":13},{"name":"in 15","type":"number","link":151,"slot_index":14},{"name":"in 16","type":"number","link":152,"slot_index":15},{"name":"in 17","type":"number","link":153,"slot_index":16},{"name":"in 18","type":"number","link":154,"slot_index":17},{"name":"in 19","type":"number","link":155,"slot_index":18},{"name":"in 20","type":"number","link":157,"slot_index":19}],"properties":{}},{"id":56,"type":"widget/number","pos":[446,1703],"size":[80,60],"flags":{},"order":20,"mode":0,"outputs":[{"name":"","type":"number","links":[91,157],"slot_index":0}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":60,"type":"features/largeinput_editor","pos":[1069.283491386718,804.9045020637204],"size":[200,410],"flags":{},"order":24,"mode":0,"inputs":[{"name":"in 1","type":"number","link":114,"slot_index":0},{"name":"in 2","type":"number","link":115,"slot_index":1},{"name":"in 3","type":"number","link":116,"slot_index":2},{"name":"in 4","type":"number","link":117,"slot_index":3},{"name":"in 5","type":"number","link":118,"slot_index":4},{"name":"in 6","type":"number","link":119,"slot_index":5},{"name":"in 7","type":"number","link":120,"slot_index":6},{"name":"in 8","type":"number","link":121,"slot_index":7},{"name":"in 9","type":"number","link":122,"slot_index":8},{"name":"in 10","type":"number","link":123,"slot_index":9},{"name":"in 11","type":"number","link":124,"slot_index":10},{"name":"in 12","type":"number","link":125,"slot_index":11},{"name":"in 13","type":"number","link":126,"slot_index":12},{"name":"in 14","type":"number","link":127,"slot_index":13},{"name":"in 15","type":"number","link":128,"slot_index":14},{"name":"in 16","type":"number","link":129,"slot_index":15},{"name":"in 17","type":"number","link":130,"slot_index":16},{"name":"in 18","type":"number","link":131,"slot_index":17},{"name":"in 19","type":"number","link":136,"slot_index":18},{"name":"in 20","type":"number","link":135,"slot_index":19}],"properties":{}},{"id":59,"type":"widget/number","pos":[942.2834913867189,139.9045020637209],"size":[80,60],"flags":{},"order":21,"mode":0,"outputs":[{"name":"","type":"number","links":[113,114,137]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":34,"type":"widget/number","pos":[354,-815],"size":[80,60],"flags":{},"order":22,"mode":0,"outputs":[{"name":"","type":"number","links":[31,51,71]}],"properties":{"min":-1000,"max":1000,"value":1,"step":1}},{"id":58,"type":"features/largeinput_editor","pos":[1066,342],"size":[200,410],"flags":{},"order":23,"mode":0,"inputs":[{"name":"in 1","type":"number","link":113,"slot_index":0},{"name":"in 2","type":"number","link":94,"slot_index":1},{"name":"in 3","type":"number","link":95,"slot_index":2},{"name":"in 4","type":"number","link":96,"slot_index":3},{"name":"in 5","type":"number","link":97,"slot_index":4},{"name":"in 6","type":"number","link":98,"slot_index":5},{"name":"in 7","type":"number","link":99,"slot_index":6},{"name":"in 8","type":"number","link":100,"slot_index":7},{"name":"in 9","type":"number","link":101,"slot_index":8},{"name":"in 10","type":"number","link":102,"slot_index":9},{"name":"in 11","type":"number","link":103,"slot_index":10},{"name":"in 12","type":"number","link":104,"slot_index":11},{"name":"in 13","type":"number","link":105,"slot_index":12},{"name":"in 14","type":"number","link":106,"slot_index":13},{"name":"in 15","type":"number","link":107,"slot_index":14},{"name":"in 16","type":"number","link":108,"slot_index":15},{"name":"in 17","type":"number","link":109,"slot_index":16},{"name":"in 18","type":"number","link":110,"slot_index":17},{"name":"in 19","type":"number","link":111,"slot_index":18},{"name":"in 20","type":"number","link":112,"slot_index":19}],"properties":{}}],"links":[[31,34,0,33,0,"number"],[32,35,0,33,1,"number"],[33,36,0,33,2,"number"],[34,37,0,33,3,"number"],[35,38,0,33,4,"number"],[36,39,0,33,5,"number"],[37,40,0,33,6,"number"],[38,41,0,33,7,"number"],[39,42,0,33,8,"number"],[40,43,0,33,9,"number"],[41,44,0,33,10,"number"],[42,45,0,33,11,"number"],[43,46,0,33,12,"number"],[44,47,0,33,13,"number"],[45,48,0,33,14,"number"],[46,49,0,33,15,"number"],[47,50,0,33,16,"number"],[48,51,0,33,17,"number"],[49,52,0,33,18,"number"],[50,53,0,33,19,"number"],[51,34,0,54,0,"number"],[52,35,0,54,1,"number"],[53,36,0,54,2,"number"],[54,37,0,54,3,"number"],[55,38,0,54,4,"number"],[56,39,0,54,5,"number"],[57,40,0,54,6,"number"],[58,41,0,54,7,"number"],[59,42,0,54,8,"number"],[60,43,0,54,9,"number"],[61,44,0,54,10,"number"],[62,45,0,54,11,"number"],[63,46,0,54,12,"number"],[64,47,0,54,13,"number"],[65,48,0,54,14,"number"],[66,49,0,54,15,"number"],[67,50,0,54,16,"number"],[68,51,0,54,17,"number"],[70,53,0,54,19,"number"],[71,34,0,55,0,"number"],[72,35,0,55,1,"number"],[73,36,0,55,2,"number"],[74,37,0,55,3,"number"],[75,38,0,55,4,"number"],[76,39,0,55,5,"number"],[77,40,0,55,6,"number"],[78,41,0,55,7,"number"],[79,42,0,55,8,"number"],[80,43,0,55,9,"number"],[81,44,0,55,10,"number"],[82,45,0,55,11,"number"],[83,46,0,55,12,"number"],[84,47,0,55,13,"number"],[85,48,0,55,14,"number"],[86,49,0,55,15,"number"],[87,50,0,55,16,"number"],[88,51,0,55,17,"number"],[89,52,0,55,18,"number"],[91,56,0,55,19,"number"],[92,57,0,54,18,"number"],[94,35,0,58,1,"number"],[95,36,0,58,2,"number"],[96,37,0,58,3,"number"],[97,38,0,58,4,"number"],[98,39,0,58,5,"number"],[99,40,0,58,6,"number"],[100,41,0,58,7,"number"],[101,42,0,58,8,"number"],[102,43,0,58,9,"number"],[103,44,0,58,10,"number"],[104,45,0,58,11,"number"],[105,46,0,58,12,"number"],[106,47,0,58,13,"number"],[107,48,0,58,14,"number"],[108,49,0,58,15,"number"],[109,50,0,58,16,"number"],[110,51,0,58,17,"number"],[111,52,0,58,18,"number"],[112,53,0,58,19,"number"],[113,59,0,58,0,"number"],[114,59,0,60,0,"number"],[115,35,0,60,1,"number"],[116,36,0,60,2,"number"],[117,37,0,60,3,"number"],[118,38,0,60,4,"number"],[119,39,0,60,5,"number"],[120,40,0,60,6,"number"],[121,41,0,60,7,"number"],[122,42,0,60,8,"number"],[123,43,0,60,9,"number"],[124,44,0,60,10,"number"],[125,45,0,60,11,"number"],[126,46,0,60,12,"number"],[127,47,0,60,13,"number"],[128,48,0,60,14,"number"],[129,49,0,60,15,"number"],[130,50,0,60,16,"number"],[131,51,0,60,17,"number"],[135,53,0,60,19,"number"],[136,57,0,60,18,"number"],[137,59,0,61,0,"number"],[138,35,0,61,1,"number"],[139,36,0,61,2,"number"],[140,37,0,61,3,"number"],[141,38,0,61,4,"number"],[142,39,0,61,5,"number"],[143,40,0,61,6,"number"],[144,41,0,61,7,"number"],[145,42,0,61,8,"number"],[146,43,0,61,9,"number"],[147,44,0,61,10,"number"],[148,45,0,61,11,"number"],[149,46,0,61,12,"number"],[150,47,0,61,13,"number"],[151,48,0,61,14,"number"],[152,49,0,61,15,"number"],[153,50,0,61,16,"number"],[154,51,0,61,17,"number"],[155,57,0,61,18,"number"],[157,56,0,61,19,"number"]],"groups":[{"title":"Use Ctrl+C/Ctrl+Shift+V to easily copy and paste new nodes maintaining connection to the outputs of unselected nodes","bounding":[1137,140,263,82],"color":"#3f789e"}],"config":{},"extra":{},"version":0.4} \ No newline at end of file diff --git a/editor/js/code.js b/editor/js/code.js index d0ead4c7b..3140e7dc7 100644 --- a/editor/js/code.js +++ b/editor/js/code.js @@ -104,6 +104,7 @@ addDemo("Audio", "examples/audio.json"); addDemo("Audio Delay", "examples/audio_delay.json"); addDemo("Audio Reverb", "examples/audio_reverb.json"); addDemo("MIDI Generation", "examples/midi_generation.json"); +addDemo("Copy Paste", "examples/copypaste.json"); addDemo("autobackup", function(){ var data = localStorage.getItem("litegraphg demo backup"); if(!data) @@ -187,4 +188,8 @@ function enableWebGL() gl.viewport(0,0,gl.canvas.width, gl.canvas.height ); } } -} \ No newline at end of file +} + +// Tests +// CopyPasteWithConnectionToUnselectedOutputTest(); +// demo(); \ No newline at end of file diff --git a/editor/js/demos.js b/editor/js/demos.js index 518d1c4db..9bd0f804c 100644 --- a/editor/js/demos.js +++ b/editor/js/demos.js @@ -43,6 +43,51 @@ function multiConnection() node_math.connect(0,node_watch2,0 ); } +function CopyPasteWithConnectionToUnselectedOutputTest() +{ + // number + var nodeConstA = LiteGraph.createNode("basic/const"); + nodeConstA.pos = [200,200]; + graph.add(nodeConstA); + nodeConstA.setValue(4.5); + + // number + var nodeConstB = LiteGraph.createNode("basic/const"); + nodeConstB.pos = [200,300]; + graph.add(nodeConstB); + nodeConstB.setValue(10); + + // math + var nodeMath = LiteGraph.createNode("math/operation"); + nodeMath.pos = [400,200]; + graph.add(nodeMath); + + // connection + nodeConstA.connect(0,nodeMath,0 ); + nodeConstB.connect(0,nodeMath,1 ); + + // copy with unselected nodes connected + graphcanvas.selectNodes([nodeMath]); + graphcanvas.copyToClipboard(); + graphcanvas.pasteFromClipboard(true); + + var count = 1; + var lastNode = null; + for (const [key, element] of Object.entries(graphcanvas.selected_nodes)) { + element.pos = [nodeMath.pos[0], nodeMath.pos[1] + 100 * count]; + lastNode = element + count++; + } + + // copy with unselected nodes unconnected + graphcanvas.pasteFromClipboard(false); + var count = 1; + for (const [key, element] of Object.entries(graphcanvas.selected_nodes)) { + element.pos = [nodeMath.pos[0], lastNode.pos[1] + 100 * count]; + count++; + } +} + function sortTest() { var rand = LiteGraph.createNode("math/rand",null, {pos: [10,100] }); @@ -227,3 +272,36 @@ TestPropertyEditorsNode.title = "Properties"; LiteGraph.registerNodeType("features/properties_editor", TestPropertyEditorsNode ); + + +//Show value inside the debug console +function LargeInputNode() +{ + this.addInput("in 1","number"); + this.addInput("in 2","number"); + this.addInput("in 3","number"); + this.addInput("in 4","number"); + this.addInput("in 5","number"); + this.addInput("in 6","number"); + this.addInput("in 7","number"); + this.addInput("in 8","number"); + this.addInput("in 9","number"); + this.addInput("in 10","number"); + this.addInput("in 11","number"); + this.addInput("in 12","number"); + this.addInput("in 13","number"); + this.addInput("in 14","number"); + this.addInput("in 15","number"); + this.addInput("in 16","number"); + this.addInput("in 17","number"); + this.addInput("in 18","number"); + this.addInput("in 19","number"); + this.addInput("in 20","number"); + this.size = [200,410]; +} + +LargeInputNode.title = "Large Input Node"; + + +LiteGraph.registerNodeType("features/largeinput_editor", LargeInputNode); + From f0eb76005e074fc81adb1bf8a92737ece85aa51e Mon Sep 17 00:00:00 2001 From: CMonk Date: Tue, 11 Apr 2023 01:21:50 +0800 Subject: [PATCH 3/3] Update guide with canvas shortcut information --- guides/README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/guides/README.md b/guides/README.md index efd2db2cc..536f4a7b6 100644 --- a/guides/README.md +++ b/guides/README.md @@ -226,6 +226,15 @@ function MyNode() this.addWidget("text","Surname","", { property: "surname"}); //this will modify the node.properties } ``` +## LGraphCanvas +LGraphCanvas is the class in charge of rendering/interaction with the nodes inside the browser. +### Canvas Shortcuts +* Space - Holding space key while moving the cursor moves the canvas around. It works when holding the mouse button down so it is easier to connect different nodes when the canvas gets too large. +* Ctrl/Shift + Click - Add clicked node to selection. +* Ctrl + A - Select all nodes +* Ctrl + C/Ctrl + V - Copy and paste selected nodes, without maintaining the connection to the outputs of unselected nodes. +* Ctrl + C/Ctrl + Shift + V - Copy and paste selected nodes, and maintaining the connection from the outputs of unselected nodes to the inputs of the newly pasted nodes. +* Holding Shift and drag selected nodes - Move multiple selected nodes at the same time. # Execution Flow To execute a graph you must call ```graph.runStep()```. @@ -320,11 +329,6 @@ this.setOutputData(0, { -``` - - - -