Skip to content

Commit

Permalink
fix(navigation/movecanvas): hook up with canvas focused state
Browse files Browse the repository at this point in the history
Related to #662
  • Loading branch information
nikku committed Dec 19, 2024
1 parent 8f4c522 commit 67484bc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/navigation/movecanvas/MoveCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function MoveCanvas(eventBus, canvas) {
// allow others to hook into the event before us though
// (dragging / element moving will do this)
eventBus.on('element.mousedown', 500, function(e) {
return handleStart(e.originalEvent);
return canvas.isFocused() && handleStart(e.originalEvent);
});


Expand Down
70 changes: 67 additions & 3 deletions test/spec/navigation/movecanvas/MoveCanvasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ describe('navigation/movecanvas', function() {
beforeEach(bootstrapDiagram({
modules: [
moveCanvasModule
]
],
config: {
canvas: {
autoFocus: true
}
}
}));

beforeEach(inject(function(canvas) {
Expand Down Expand Up @@ -93,7 +98,12 @@ describe('navigation/movecanvas', function() {
beforeEach(bootstrapDiagram({
modules: [
moveCanvasModule
]
],
config: {
canvas: {
autoFocus: true
}
}
}));

beforeEach(inject(function(canvas) {
Expand Down Expand Up @@ -130,7 +140,12 @@ describe('navigation/movecanvas', function() {
modules: [
moveCanvasModule,
interactionEventsModule
]
],
config: {
canvas: {
autoFocus: true
}
}
}));


Expand All @@ -153,6 +168,55 @@ describe('navigation/movecanvas', function() {

});


describe('integration - canvas focus', function() {

beforeEach(bootstrapDiagram({
modules: [
moveCanvasModule,
interactionEventsModule
]
}));


it('should not activate if canvas is not focused', inject(
function(eventBus, canvas, moveCanvas) {

// given
var rootElement = canvas.getRootElement();

eventBus.fire(mouseDownEvent(rootElement, { clientX: 0, clientY: 0 }));

// when
document.dispatchEvent(createMouseEvent(200, 100, 'mousemove'));

// then
expect(moveCanvas.isActive()).to.be.false;
}
));


it('should activate if canvas is focused', inject(
function(eventBus, canvas, moveCanvas) {

// given
var rootElement = canvas.getRootElement();

// when
canvas.focus();

eventBus.fire(mouseDownEvent(rootElement, { clientX: 0, clientY: 0 }));

// and
document.dispatchEvent(createMouseEvent(200, 100, 'mousemove'));

// then
expect(moveCanvas.isActive()).to.be.true;
}
));

});

});


Expand Down

0 comments on commit 67484bc

Please sign in to comment.