-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(keyboard): move arrow bindings to keyboard-move feature
Moving canvas with keyboard will now be controlled by KeyboardMove feature. To use it, press Cmd/Ctrl and arrows. Use Shift for accelerated move speed. Configure speed by adding `keyboardMove` to `config` with following properties: - moveSpeed - moveSpeedAccelerated BREAKING CHANGES: - remove canvas movement controls from Keyboard - move canvas with keyboard arrows and Cmd/Ctrl
- Loading branch information
Showing
6 changed files
with
397 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { assign } from 'min-dash'; | ||
|
||
|
||
var DEFAULT_CONFIG = { | ||
moveSpeed: 50, | ||
moveSpeedAccelerated: 200 | ||
}; | ||
|
||
|
||
/** | ||
* | ||
* @param {Object} config | ||
* @param {Number} [config.moveSpeed=50] | ||
* @param {Number} [config.moveSpeedAccelerated=200] | ||
* @param {Keyboard} keyboard | ||
* @param {EditorActions} editorActions | ||
*/ | ||
export default function KeyboardNavigation( | ||
config, | ||
keyboard, | ||
editorActions | ||
) { | ||
|
||
var self = this; | ||
|
||
this._config = assign({}, DEFAULT_CONFIG, config || {}); | ||
|
||
keyboard.addListener(arrowsListener); | ||
|
||
|
||
function arrowsListener(context) { | ||
|
||
var event = context.event, | ||
config = self._config; | ||
|
||
if (!keyboard.isCmd(event)) { | ||
return; | ||
} | ||
|
||
if (keyboard.isKey([ | ||
'ArrowLeft', 'Left', | ||
'ArrowUp', 'Up', | ||
'ArrowDown', 'Down', | ||
'ArrowRight', 'Right' | ||
], event)) { | ||
|
||
var opts = { | ||
speed: keyboard.isShift(event) ? config.moveSpeedAccelerated : config.moveSpeed | ||
}; | ||
|
||
switch (event.key) { | ||
case 'ArrowLeft': | ||
case 'Left': | ||
opts.direction = 'left'; | ||
break; | ||
case 'ArrowUp': | ||
case 'Up': | ||
opts.direction = 'up'; | ||
break; | ||
case 'ArrowRight': | ||
case 'Right': | ||
opts.direction = 'right'; | ||
break; | ||
case 'ArrowDown': | ||
case 'Down': | ||
opts.direction = 'down'; | ||
break; | ||
} | ||
|
||
editorActions.trigger('moveCanvas', opts); | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
||
|
||
KeyboardNavigation.$inject = [ | ||
'config.keyboardMove', | ||
'keyboard', | ||
'editorActions' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import EditorActions from '../../features/editor-actions'; | ||
import KeyboardModule from '../../features/keyboard'; | ||
|
||
import KeyboardMove from './KeyboardMove'; | ||
|
||
|
||
export default { | ||
__depends__: [ | ||
EditorActions, | ||
KeyboardModule | ||
], | ||
__init__: [ 'keyboardMove' ], | ||
keyboardMove: [ 'type', KeyboardMove ] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.