1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 22:40:55 +01:00
phorge-phorge/webroot/rsrc/js/application/differential/behavior-keyboard-nav.js

49 lines
993 B
JavaScript
Raw Normal View History

/**
* @provides javelin-behavior-differential-keyboard-navigation
* @requires javelin-behavior
* javelin-dom
* phabricator-keyboard-shortcut
*/
JX.behavior('differential-keyboard-navigation', function(config) {
var cursor = null;
var changesets;
function init() {
if (changesets) {
return;
}
changesets = JX.DOM.scry(document.body, 'div', 'differential-changeset');
}
function jump(manager, delta) {
init();
if (cursor === null) {
cursor = -1;
}
cursor = (cursor + changesets.length + delta) % changesets.length;
var selected = changesets[cursor];
manager.scrollTo(selected);
manager.focusOn(selected);
}
new JX.KeyboardShortcut('j', 'Jump to next change.')
.setHandler(function(manager) {
jump(manager, 1);
})
.register();
new JX.KeyboardShortcut('k', 'Jump to previous change.')
.setHandler(function(manager) {
jump(manager, -1);
})
.register();
});