Skip to content

Commit

Permalink
feat(space-tool): make local by default
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and nikku committed Oct 18, 2023
1 parent 8f7f91a commit 60b2c77
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/features/space-tool/SpaceTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ SpaceTool.prototype.init = function(event, context) {

var root = this._canvas.getRootElement();

if (hasSecondaryModifier(event) && event.hover) {
if (!hasSecondaryModifier(event) && event.hover) {
root = event.hover;
}

Expand Down
109 changes: 81 additions & 28 deletions test/spec/features/space-tool/SpaceToolSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ describe('features/space-tool', function() {
});


describe('create/remove space - global', function() {
describe('create/remove space', function() {

beforeEach(bootstrapDiagram({
modules: [
Expand Down Expand Up @@ -874,7 +874,7 @@ describe('features/space-tool', function() {
});


describe('create/remove space - local', function() {
describe('create/remove space - local and global', function() {

beforeEach(bootstrapDiagram({
modules: [
Expand Down Expand Up @@ -925,7 +925,41 @@ describe('features/space-tool', function() {
}));


it('should create space locally', inject(
it('should create space locally by default', inject(
function(dragging, spaceTool) {

// given
spaceTool.activateMakeSpace(canvasEvent({ x: 110, y: 0 }));

dragging.hover({
element: childShape2
});

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

dragging.end();

// then
expect(childShape.x).to.equal(100);
expect(childShape.y).to.equal(100);
expect(childShape.width).to.equal(200);
expect(childShape.height).to.equal(100);

expect(childShape2.x).to.equal(100);
expect(childShape2.y).to.equal(300);
expect(childShape2.width).to.equal(300);
expect(childShape2.height).to.equal(100);

expect(grandChildShape.x).to.equal(325);
expect(grandChildShape.y).to.equal(325);
expect(grandChildShape.width).to.equal(50);
expect(grandChildShape.height).to.equal(50);
}
));


it('should create space globally', inject(
function(dragging, spaceTool) {

// given
Expand All @@ -946,7 +980,7 @@ describe('features/space-tool', function() {
// then
expect(childShape.x).to.equal(100);
expect(childShape.y).to.equal(100);
expect(childShape.width).to.equal(200);
expect(childShape.width).to.equal(300);
expect(childShape.height).to.equal(100);

expect(childShape2.x).to.equal(100);
Expand All @@ -962,7 +996,7 @@ describe('features/space-tool', function() {
));


it('should remove space locally', inject(
it('should remove space locally by default', inject(
function(dragging, spaceTool) {

// given
Expand All @@ -973,10 +1007,7 @@ describe('features/space-tool', function() {
});

// when
dragging.move(canvasEvent({ x: 110, y: 0 }, {
button: 0,
shiftKey: true
}));
dragging.move(canvasEvent({ x: 110, y: 0 }));

dragging.end();

Expand All @@ -999,40 +1030,39 @@ describe('features/space-tool', function() {
));


it('should move attachers', inject(
function(canvas, dragging, elementFactory, spaceTool) {
it('should remove space globally', inject(
function(dragging, spaceTool) {

// given
var attacher = elementFactory.createShape({
id: 'attacher',
x: 275,
y: 375,
width: 50,
height: 50,
host: childShape2
});

canvas.addShape(attacher);

spaceTool.activateMakeSpace(canvasEvent({ x: 110, y: 0 }));
spaceTool.activateMakeSpace(canvasEvent({ x: 210, y: 0 }));

dragging.hover({
element: childShape2
});

// when
dragging.move(canvasEvent({ x: 210, y: 0 }, {
dragging.move(canvasEvent({ x: 110, y: 0 }, {
button: 0,
shiftKey: true
}));

dragging.end();

// then
expect(attacher.x).to.equal(375);
expect(attacher.y).to.equal(375);
expect(attacher.width).to.equal(50);
expect(attacher.height).to.equal(50);
expect(childShape.x).to.equal(100);
expect(childShape.y).to.equal(100);
expect(childShape.width).to.equal(100);
expect(childShape.height).to.equal(100);

expect(childShape2.x).to.equal(100);
expect(childShape2.y).to.equal(300);
expect(childShape2.width).to.equal(100);
expect(childShape2.height).to.equal(100);

expect(grandChildShape.x).to.equal(125);
expect(grandChildShape.y).to.equal(325);
expect(grandChildShape.width).to.equal(50);
expect(grandChildShape.height).to.equal(50);
}
));

Expand Down Expand Up @@ -1286,6 +1316,29 @@ describe('features/space-tool', function() {
}));


it('should move attacher of resizing root', inject(function(dragging, spaceTool) {

// when
spaceTool.activateMakeSpace(canvasEvent({ x: 250, y: 0 }));

dragging.hover({
element: parent
});

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

dragging.end();

// then
expect(parentAttacher).to.have.bounds({
x: 425,
y: 275,
width: 50,
height: 50
});
}));


it('should not move attacher', inject(function(dragging, spaceTool) {

// when
Expand Down

0 comments on commit 60b2c77

Please sign in to comment.