From 6ebd3a571af1f1dccdb2a9d7d13fcd3941e4a702 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Mon, 14 Oct 2019 09:43:46 +0200 Subject: [PATCH] fix(create): cancel create on Related to camunda/camunda-modeler#1466 --- lib/features/create/Create.js | 25 ++++++++++++++++++++++++- test/spec/features/create/CreateSpec.js | 15 +++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/features/create/Create.js b/lib/features/create/Create.js index a77345cba..507f3a023 100644 --- a/lib/features/create/Create.js +++ b/lib/features/create/Create.js @@ -15,6 +15,10 @@ import { import { getBBox } from '../../util/Elements'; +var PREFIX = 'create'; + +var HIGH_PRIORITY = 2000; + /** * Create new elements through drag and drop. @@ -224,6 +228,25 @@ export default function Create( }); }); + function cancel() { + var context = dragging.context(); + + if (context && context.prefix === PREFIX) { + dragging.cancel(); + } + } + + // cancel on that is not result of + eventBus.on('elements.changed', cancel); + + eventBus.on('create.end', HIGH_PRIORITY, function() { + eventBus.off('elements.changed', cancel); + }); + + eventBus.on('create.ended', function() { + eventBus.on('elements.changed', cancel); + }); + // API ////////// this.start = function(event, elements, context) { @@ -277,7 +300,7 @@ export default function Create( }); }); - dragging.init(event, 'create', { + dragging.init(event, PREFIX, { cursor: 'grabbing', autoActivate: true, data: { diff --git a/test/spec/features/create/CreateSpec.js b/test/spec/features/create/CreateSpec.js index 8f2bf6917..6fa77da0c 100644 --- a/test/spec/features/create/CreateSpec.js +++ b/test/spec/features/create/CreateSpec.js @@ -323,6 +323,21 @@ describe('features/create - Create', function() { expect(context.shape).to.equal(newShape2); })); + + it('should cancel on ', inject( + function(create, dragging, elementRegistry, eventBus) { + + // given + create.start(canvasEvent({ x: 0, y: 0 }), newShape); + + // when + eventBus.fire('elements.changed', { elements: [] }); + + // then + expect(dragging.context()).not.to.exist; + } + )); + });