Skip to content

Commit

Permalink
feat(editor): Move canvas by holding Space or Middle mouse button (#5719
Browse files Browse the repository at this point in the history
)

* ⚡ Implemented canvas move on space+drag
* ⚡ Added middle mouse key canvas move
* ⚡ Handling cursor changes when moving canvas with middle mouse button
* 💄 Consolidate naming
  • Loading branch information
MiloradFilipovic authored Mar 17, 2023
1 parent 6242cac commit 19dded1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/editor-ui/src/mixins/mouseSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export const mouseSelect = mixins(deviceSupportHelpers).extend({

return returnNodes;
},
mouseDownMouseSelect(e: MouseEvent) {
if (this.isCtrlKeyPressed(e) === true) {
mouseDownMouseSelect(e: MouseEvent, moveButtonPressed: boolean) {
if (this.isCtrlKeyPressed(e) === true || moveButtonPressed) {
// We only care about it when the ctrl key is not pressed at the same time.
// So we exit when it is pressed.
return;
Expand Down
14 changes: 11 additions & 3 deletions packages/editor-ui/src/mixins/moveNodeWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const moveNodeWorkflow = mixins(deviceSupportHelpers).extend({
this.moveLastPosition[0] = x;
this.moveLastPosition[1] = y;
},
mouseDownMoveWorkflow(e: MouseEvent) {
if (this.isCtrlKeyPressed(e) === false) {
mouseDownMoveWorkflow(e: MouseEvent, moveButtonPressed: boolean) {
if (this.isCtrlKeyPressed(e) === false && !moveButtonPressed) {
// We only care about it when the ctrl key is pressed at the same time.
// So we exit when it is not pressed.
return;
Expand All @@ -39,7 +39,10 @@ export const moveNodeWorkflow = mixins(deviceSupportHelpers).extend({
return;
}

this.uiStore.nodeViewMoveInProgress = true;
// Don't indicate move start just yet if middle button is pressed
if (e.button !== 1) {
this.uiStore.nodeViewMoveInProgress = true;
}

const [x, y] = getMousePosition(e);

Expand Down Expand Up @@ -73,6 +76,11 @@ export const moveNodeWorkflow = mixins(deviceSupportHelpers).extend({
return;
}

// Signal that moving canvas is active if middle button is pressed and mouse is moved
if (e.button === 1) {
this.uiStore.nodeViewMoveInProgress = true;
}

if (e.buttons === 0) {
// Mouse button is not pressed anymore so stop selection mode
// Happens normally when mouse leave the view pressed and then
Expand Down
20 changes: 16 additions & 4 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,14 @@ export default mixins(
},
workflowClasses() {
const returnClasses = [];
if (this.ctrlKeyPressed) {
if (this.ctrlKeyPressed || this.moveCanvasKeyPressed) {
if (this.uiStore.nodeViewMoveInProgress === true) {
returnClasses.push('move-in-process');
} else {
returnClasses.push('move-active');
}
}
if (this.selectActive || this.ctrlKeyPressed) {
if (this.selectActive || this.ctrlKeyPressed || this.moveCanvasKeyPressed) {
// Makes sure that nothing gets selected while select or move is active
returnClasses.push('do-not-select');
}
Expand Down Expand Up @@ -595,6 +595,7 @@ export default mixins(
lastSelectedConnection: null as null | Connection,
lastClickPosition: [450, 450] as XYPosition,
ctrlKeyPressed: false,
moveCanvasKeyPressed: false,
stopExecutionInProgress: false,
blankRedirect: false,
credentialsUpdated: false,
Expand Down Expand Up @@ -971,21 +972,30 @@ export default mixins(
mouseDown(e: MouseEvent | TouchEvent) {
// Save the location of the mouse click
this.lastClickPosition = this.getMousePositionWithinNodeView(e);
if (e instanceof MouseEvent && e.button === 1) {
this.moveCanvasKeyPressed = true;
}
this.mouseDownMouseSelect(e as MouseEvent);
this.mouseDownMoveWorkflow(e as MouseEvent);
this.mouseDownMouseSelect(e as MouseEvent, this.moveCanvasKeyPressed);
this.mouseDownMoveWorkflow(e as MouseEvent, this.moveCanvasKeyPressed);
// Hide the node-creator
this.createNodeActive = false;
},
mouseUp(e: MouseEvent) {
if (e.button === 1) {
this.moveCanvasKeyPressed = false;
}
this.mouseUpMouseSelect(e);
this.mouseUpMoveWorkflow(e);
},
keyUp(e: KeyboardEvent) {
if (e.key === this.controlKeyCode) {
this.ctrlKeyPressed = false;
}
if (e.key === ' ') {
this.moveCanvasKeyPressed = false;
}
},
async keyDown(e: KeyboardEvent) {
// @ts-ignore
Expand Down Expand Up @@ -1037,6 +1047,8 @@ export default mixins(
});
} else if (e.key === this.controlKeyCode) {
this.ctrlKeyPressed = true;
} else if (e.key === ' ') {
this.moveCanvasKeyPressed = true;
} else if (e.key === 'F2' && !this.isReadOnly) {
const lastSelectedNode = this.lastSelectedNode;
if (lastSelectedNode !== null && lastSelectedNode.type !== STICKY_NODE_TYPE) {
Expand Down

0 comments on commit 19dded1

Please sign in to comment.