1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3729 from node-red/cut-vs-copy

Do not generate new node-ids when pasting a cut flow
This commit is contained in:
Stephen McLaughlin 2022-07-06 10:36:14 +01:00 committed by GitHub
commit 8cb212d897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,6 +95,7 @@ RED.view = (function() {
let flashingNodeId; let flashingNodeId;
var clipboard = ""; var clipboard = "";
let clipboardSource
// Note: these are the permitted status colour aliases. The actual RGB values // Note: these are the permitted status colour aliases. The actual RGB values
// are set in the CSS - flow.scss/colors.scss // are set in the CSS - flow.scss/colors.scss
@ -628,8 +629,10 @@ RED.view = (function() {
}); });
RED.actions.add("core:copy-selection-to-internal-clipboard",copySelection); RED.actions.add("core:copy-selection-to-internal-clipboard",copySelection);
RED.actions.add("core:cut-selection-to-internal-clipboard",function(){copySelection();deleteSelection();}); RED.actions.add("core:cut-selection-to-internal-clipboard",function(){copySelection(true);deleteSelection();});
RED.actions.add("core:paste-from-internal-clipboard",function(){importNodes(clipboard,{generateIds: true, generateDefaultNames: true});}); RED.actions.add("core:paste-from-internal-clipboard",function(){
importNodes(clipboard,{generateIds: clipboardSource === 'copy', generateDefaultNames: clipboardSource === 'copy'});
});
RED.actions.add("core:detach-selected-nodes", function() { detachSelectedNodes() }) RED.actions.add("core:detach-selected-nodes", function() { detachSelectedNodes() })
@ -2149,6 +2152,9 @@ RED.view = (function() {
} }
} }
if (mouse_mode == RED.state.IMPORT_DRAGGING) { if (mouse_mode == RED.state.IMPORT_DRAGGING) {
if (clipboardSource === 'cut') {
clipboardSource = 'copy'
}
updateActiveNodes(); updateActiveNodes();
RED.nodes.dirty(true); RED.nodes.dirty(true);
} }
@ -2703,7 +2709,7 @@ RED.view = (function() {
} }
} }
function copySelection() { function copySelection(isCut) {
if (mouse_mode === RED.state.SELECTING_NODE) { if (mouse_mode === RED.state.SELECTING_NODE) {
return; return;
} }
@ -2767,6 +2773,7 @@ RED.view = (function() {
} }
} }
clipboard = JSON.stringify(nns); clipboard = JSON.stringify(nns);
clipboardSource = isCut ? 'cut' : 'copy'
RED.menu.setDisabled("menu-item-edit-paste", false); RED.menu.setDisabled("menu-item-edit-paste", false);
if (nodeCount > 0) { if (nodeCount > 0) {
RED.notify(RED._("clipboard.nodeCopied",{count:nodeCount}),{id:"clipboard"}); RED.notify(RED._("clipboard.nodeCopied",{count:nodeCount}),{id:"clipboard"});
@ -3477,6 +3484,9 @@ RED.view = (function() {
updateSelection(); updateSelection();
RED.nodes.dirty(true); RED.nodes.dirty(true);
redraw(); redraw();
if (clipboardSource === 'cut') {
clipboardSource = 'copy'
}
resetMouseVars(); resetMouseVars();
d3.event.stopPropagation(); d3.event.stopPropagation();
return; return;
@ -4086,7 +4096,7 @@ RED.view = (function() {
var mdn = mousedown_node; var mdn = mousedown_node;
var options = []; var options = [];
options.push({name:"delete",disabled:(movingSet.length()===0 && selectedLinks.length() === 0),onselect:function() {deleteSelection();}}); options.push({name:"delete",disabled:(movingSet.length()===0 && selectedLinks.length() === 0),onselect:function() {deleteSelection();}});
options.push({name:"cut",disabled:(movingSet.length()===0),onselect:function() {copySelection();deleteSelection();}}); options.push({name:"cut",disabled:(movingSet.length()===0),onselect:function() {copySelection(true);deleteSelection();}});
options.push({name:"copy",disabled:(movingSet.length()===0),onselect:function() {copySelection();}}); options.push({name:"copy",disabled:(movingSet.length()===0),onselect:function() {copySelection();}});
options.push({name:"paste",disabled:(clipboard.length===0),onselect:function() {importNodes(clipboard, {generateIds: true, touchImport: true});}}); options.push({name:"paste",disabled:(clipboard.length===0),onselect:function() {importNodes(clipboard, {generateIds: true, touchImport: true});}});
options.push({name:"edit",disabled:(movingSet.length() != 1),onselect:function() { RED.editor.edit(mdn);}}); options.push({name:"edit",disabled:(movingSet.length() != 1),onselect:function() { RED.editor.edit(mdn);}});