Skip to content

Commit

Permalink
chore: early abort alignment if no elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku authored and fake-join[bot] committed Mar 3, 2021
1 parent a5015bf commit d6c5580
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/align-to-origin.js
Expand Up @@ -89,6 +89,10 @@ export default function AlignToOrigin(config, injector, eventBus, commandStack,

var elements = canvas.getRootElement().children;

if (!elements.length) {
return;
}

var delta = computeAdjustment(bounds, config);

if (delta.x === 0 && delta.y === 0) {
Expand Down
13 changes: 13 additions & 0 deletions test/spec/AlignToOrigin.event.bpmn
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="8.2.0">
<process id="Process_1" isExecutable="false">
<startEvent id="Event" />
</process>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Event_di" bpmnElement="Event">
<omgdc:Bounds x="300" y="200" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
30 changes: 30 additions & 0 deletions test/spec/AlignToOrigin.spec.js
Expand Up @@ -160,4 +160,34 @@ describe('alignToOrigin', function() {

});


it('should handle last element removal', async function() {

// given
var diagramXML = require('./AlignToOrigin.event.bpmn');

var modeler = new BpmnModeler({
container: 'body',
additionalModules: [
AlignToOriginModule
]
});

await modeler.importXML(diagramXML);

var elementRegistry = modeler.get('elementRegistry');
var modeling = modeler.get('modeling');
var commandStack = modeler.get('commandStack');

// when
modeling.removeElements([
elementRegistry.get('Event')
]);

commandStack.undo();

// then
expect(elementRegistry.get('Event')).to.exist;
});

});

0 comments on commit d6c5580

Please sign in to comment.