Skip to content

Commit

Permalink
feat(move): do not move if no delta
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 d8f7dbc commit c0c2b4f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/features/move/Move.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ export default function MoveEvents(
delta.x = round(delta.x);
delta.y = round(delta.y);

if (delta.x === 0 && delta.y === 0) {

// didn't move
return;
}

modeling.moveElements(shapes, delta, context.target, {
primaryShape: context.shape,
attach: isAttach
Expand Down
34 changes: 34 additions & 0 deletions test/spec/features/move/MoveSpec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global sinon */

import {
bootstrapDiagram,
inject
Expand All @@ -15,6 +17,8 @@ import {
import modelingModule from 'lib/features/modeling';
import moveModule from 'lib/features/move';

var spy = sinon.spy;


describe('features/move - Move', function() {

Expand Down Expand Up @@ -106,6 +110,7 @@ describe('features/move - Move', function() {

});


describe('modeling', function() {

it('should round movement to pixels', inject(function(move, dragging, elementRegistry) {
Expand Down Expand Up @@ -144,6 +149,35 @@ describe('features/move - Move', function() {
expect(dragging.context().data.context).to.include(context);
}));


it('should NOT move if no delta', inject(
function(dragging, elementRegistry, modeling, move) {

// given
var moveElementsSpy = spy(modeling, 'moveElements');

move.start(canvasEvent({ x: 0, y: 0 }), childShape);

// when
dragging.move(canvasEvent({ x: 20, y: 20 }));

dragging.hover({
element: parentShape,
gfx: elementRegistry.getGraphics(parentShape)
});

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

dragging.end();

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

expect(childShape.x).to.eql(110);
expect(childShape.y).to.eql(110);
}
));

});

});

0 comments on commit c0c2b4f

Please sign in to comment.