Skip to content

Commit

Permalink
Issue #658 - Support shift+UP/RIGHT/DOWN/LEFT to move the viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
juliandescottes committed Jun 10, 2017
1 parent c2dbddc commit b21ea30
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/js/controller/DrawingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.RESET_ZOOM, this.resetZoom_.bind(this));
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.INCREASE_ZOOM, this.updateZoom_.bind(this, 1));
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.DECREASE_ZOOM, this.updateZoom_.bind(this, -1));
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.OFFSET_UP, this.updateOffset_.bind(this, 'up'));
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.OFFSET_RIGHT, this.updateOffset_.bind(this, 'right'));
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.OFFSET_DOWN, this.updateOffset_.bind(this, 'down'));
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.OFFSET_LEFT, this.updateOffset_.bind(this, 'left'));

window.setTimeout(function () {
this.afterWindowResize_();
Expand Down Expand Up @@ -262,6 +266,29 @@
this.updateZoom_(modifier, coords);
};

/**
* Update the current viewport offset of 1 pixel in the provided direction.
* Direction can be one of 'up', 'right', 'down', 'left'.
* Callback for the OFFSET_${DIR} shortcuts.
*/
ns.DrawingController.prototype.updateOffset_ = function (direction) {
var off = this.getOffset();
if (direction === 'up') {
off.y -= 1;
} else if (direction === 'right') {
off.x += 1;
} else if (direction === 'down') {
off.y += 1;
} else if (direction === 'left') {
off.x -= 1;
}

this.setOffset(
off.x,
off.y
);
};

/**
* Update the current zoom level by a given multiplier.
*
Expand Down
6 changes: 5 additions & 1 deletion src/js/service/keyboard/Shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
ONION_SKIN : createShortcut('onion-skin', 'Toggle onion skin', 'alt+O'),
LAYER_PREVIEW : createShortcut('layer-preview', 'Toggle layer preview', 'alt+L'),
MERGE_ANIMATION : createShortcut('import-animation', 'Open merge animation popup', 'ctrl+shift+M'),
CLOSE_POPUP : createShortcut('close-popup', 'Close an opened popup', 'ESC')
CLOSE_POPUP : createShortcut('close-popup', 'Close an opened popup', 'ESC'),
OFFSET_UP : createShortcut('move-up', 'Move viewport up', 'shift+up'),
OFFSET_RIGHT : createShortcut('move-right', 'Move viewport right', 'shift+right'),
OFFSET_DOWN : createShortcut('move-down', 'Move viewport down', 'shift+down'),
OFFSET_LEFT : createShortcut('move-left', 'Move viewport left', 'shift+left'),
},

STORAGE : {
Expand Down

0 comments on commit b21ea30

Please sign in to comment.