Skip to content

Commit

Permalink
feat(resize): don't resize if bounds haven't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and merge-me[bot] committed Jun 5, 2019
1 parent c0c2b4f commit e5cdb15
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/features/resize/Resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,17 @@ export default function Resize(eventBus, rules, modeling, dragging) {
newBounds = context.newBounds;

if (canExecute) {

// ensure we have actual pixel values for new bounds
// (important when zoom level was > 1 during move)
newBounds = roundBounds(newBounds);

if (!boundsChanged(shape, newBounds)) {

// no resize necessary
return;
}

// perform the actual resize
modeling.resizeShape(shape, newBounds);
}
Expand Down Expand Up @@ -229,4 +236,13 @@ Resize.$inject = [
'rules',
'modeling',
'dragging'
];
];

// helpers //////////

function boundsChanged(shape, newBounds) {
return shape.x !== newBounds.x ||
shape.y !== newBounds.y ||
shape.width !== newBounds.width ||
shape.height !== newBounds.height;
}
43 changes: 43 additions & 0 deletions test/spec/features/resize/ResizeSpec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global sinon */

import {
bootstrapDiagram,
inject
Expand Down Expand Up @@ -25,6 +27,8 @@ function bounds(b) {
return pick(b, [ 'x', 'y', 'width', 'height' ]);
}

var spy = sinon.spy;

describe('features/resize - Resize', function() {

beforeEach(bootstrapDiagram({
Expand Down Expand Up @@ -203,6 +207,45 @@ describe('features/resize - Resize', function() {
expect(shapeBounds).to.eql({ x: 100, y: 100, width: 80, height: 110 });
}));


it('should NOT resize if bounds have not changed', inject(
function(canvas, dragging, elementFactory, modeling, resize) {

// given
var resizeShapeSpy = spy(modeling, 'resizeShape');

var shape = elementFactory.createShape({
id: 'shapeA',
resizable: 'always',
x: 100,
y: 100,
width: 100,
height: 100
});

shape = canvas.addShape(shape);

// when
resize.activate(canvasEvent({ x: 200, y: 200 }), shape, 'se');

dragging.move(canvasEvent({ x: 205, y: 205 }));

dragging.move(canvasEvent({ x: 200, y: 200 }));

dragging.end();

// then
expect(resizeShapeSpy).not.to.have.been.called;

expect(shape).to.have.bounds({
x: 100,
y: 100,
width: 100,
height: 100
});
}
));

});


Expand Down

0 comments on commit e5cdb15

Please sign in to comment.