diff --git a/lib/features/resize/Resize.js b/lib/features/resize/Resize.js index 672a1b605..963f67e0c 100644 --- a/lib/features/resize/Resize.js +++ b/lib/features/resize/Resize.js @@ -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); } @@ -229,4 +236,13 @@ Resize.$inject = [ 'rules', 'modeling', 'dragging' -]; \ No newline at end of file +]; + +// helpers ////////// + +function boundsChanged(shape, newBounds) { + return shape.x !== newBounds.x || + shape.y !== newBounds.y || + shape.width !== newBounds.width || + shape.height !== newBounds.height; +} \ No newline at end of file diff --git a/test/spec/features/resize/ResizeSpec.js b/test/spec/features/resize/ResizeSpec.js index 9ab8fcce3..4cdbdc17b 100644 --- a/test/spec/features/resize/ResizeSpec.js +++ b/test/spec/features/resize/ResizeSpec.js @@ -1,3 +1,5 @@ +/* global sinon */ + import { bootstrapDiagram, inject @@ -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({ @@ -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 + }); + } + )); + });