From 8e55edd80f5c2e9a260485fb42ba2cf4262d4262 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Fri, 19 May 2017 12:55:46 +0200 Subject: [PATCH] chore(copy-paste): temporarily prevent consecutive paste This prevents users from creating invalid models due to IDs not properly being generated on consecutive paste (#686). Closes #688. --- lib/features/copy-paste/BpmnCopyPaste.js | 13 ++++++-- .../features/copy-paste/BpmnCopyPasteSpec.js | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/features/copy-paste/BpmnCopyPaste.js b/lib/features/copy-paste/BpmnCopyPaste.js index cdf9c538..18af2ff1 100644 --- a/lib/features/copy-paste/BpmnCopyPaste.js +++ b/lib/features/copy-paste/BpmnCopyPaste.js @@ -30,7 +30,9 @@ function removeProperties(element, properties) { }); } -function BpmnCopyPaste(bpmnFactory, eventBus, copyPaste, clipboard, moddle, canvas, bpmnRules) { +function BpmnCopyPaste( + bpmnFactory, eventBus, copyPaste, + clipboard, canvas, bpmnRules) { var helper = new ModelCloneHelper(eventBus); @@ -138,6 +140,14 @@ function BpmnCopyPaste(bpmnFactory, eventBus, copyPaste, clipboard, moddle, canv 'triggeredByEvent' ]); }); + + + eventBus.on('commandStack.elements.paste.postExecuted', function() { + // temporarily disable multi paste until #686 + // is addressed + clipboard.clear(); + }); + } @@ -146,7 +156,6 @@ BpmnCopyPaste.$inject = [ 'eventBus', 'copyPaste', 'clipboard', - 'moddle', 'canvas', 'bpmnRules' ]; diff --git a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js index 6d578f52..21ecc78a 100644 --- a/test/spec/features/copy-paste/BpmnCopyPasteSpec.js +++ b/test/spec/features/copy-paste/BpmnCopyPasteSpec.js @@ -58,6 +58,38 @@ describe('features/copy-paste', function() { }); + it('should forbid multi paste', inject( + function(elementRegistry, canvas, copyPaste) { + // given + var element = elementRegistry.get('SubProcess_1kd6ist'), + rootElement = canvas.getRootElement(); + + // when + copyPaste.copy(element); + + copyPaste.paste({ + element: rootElement, + point: { + x: 600, + y: 100 + } + }); + + copyPaste.paste({ + element: rootElement, + point: { + x: 600, + y: 275 + } + }); + + // then + // pasted was only once + expect(rootElement.children).to.have.length(2); + } + )); + + describe('integration', function() { it('should retain label\'s relative position', @@ -489,6 +521,7 @@ describe('features/copy-paste', function() { it('multiple participants', inject(integrationTest([ 'Participant_0pgdgt4', 'Participant_1id96b4' ]))); it('multiple participants', inject(integrationTest([ 'Participant_0pgdgt4', 'Participant_1id96b4' ]))); + }); });