mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 15:30:58 +01:00
Allow "J" and "K" to jump between files in Differential
Summary: Provide a more coarse keyboard navigation option to jump between files. Test Plan: - Used "j" and "k" to jump between changes in files. - Used "J" and "K" to jump between files. - Pressed "?" and read help about this. Reviewed By: jungejason Reviewers: jungejason, tuomaspelkonen, aran Commenters: fzamore CC: aran, epriestley, jungejason, fzamore Differential Revision: 764
This commit is contained in:
parent
054ac65a9d
commit
24390d2b40
1 changed files with 46 additions and 18 deletions
|
@ -8,9 +8,11 @@
|
|||
JX.behavior('differential-keyboard-navigation', function(config) {
|
||||
|
||||
var cursor = -1;
|
||||
var cursor_block = null;
|
||||
var changesets;
|
||||
|
||||
var selection_begin = null;
|
||||
var selection_end = null;
|
||||
|
||||
function init() {
|
||||
if (changesets) {
|
||||
return;
|
||||
|
@ -53,6 +55,10 @@ JX.behavior('differential-keyboard-navigation', function(config) {
|
|||
return 'ignore';
|
||||
}
|
||||
|
||||
if (row.className.indexOf('differential-changeset') !== -1) {
|
||||
return 'file';
|
||||
}
|
||||
|
||||
var cells = JX.DOM.scry(row, 'td');
|
||||
|
||||
for (var ii = 0; ii < cells.length; ii++) {
|
||||
|
@ -67,7 +73,7 @@ JX.behavior('differential-keyboard-navigation', function(config) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function jump(manager, delta) {
|
||||
function jump(manager, delta, jump_to_file) {
|
||||
init();
|
||||
|
||||
if (cursor < 0) {
|
||||
|
@ -79,8 +85,6 @@ JX.behavior('differential-keyboard-navigation', function(config) {
|
|||
}
|
||||
}
|
||||
|
||||
var selected;
|
||||
var extent;
|
||||
while (true) {
|
||||
var blocks = getBlocks(cursor);
|
||||
var focus;
|
||||
|
@ -91,31 +95,42 @@ JX.behavior('differential-keyboard-navigation', function(config) {
|
|||
}
|
||||
|
||||
for (var ii = 0; ii < blocks.length; ii++) {
|
||||
if (blocks[ii][0] == cursor_block) {
|
||||
if (blocks[ii][0] == selection_begin) {
|
||||
focus = ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
focus += delta;
|
||||
while (true) {
|
||||
focus += delta;
|
||||
|
||||
if (blocks[focus]) {
|
||||
var row_type = getRowType(blocks[focus][0]);
|
||||
if (jump_to_file && row_type != 'file') {
|
||||
continue;
|
||||
}
|
||||
|
||||
selection_begin = blocks[focus][0];
|
||||
selection_end = blocks[focus][1];
|
||||
|
||||
manager.scrollTo(selection_begin);
|
||||
manager.focusOn(selection_begin, selection_end);
|
||||
|
||||
if (blocks[focus]) {
|
||||
selected = blocks[focus][0];
|
||||
extent = blocks[focus][1];
|
||||
cursor_block = selected;
|
||||
break;
|
||||
} else {
|
||||
var adjusted = (cursor + delta);
|
||||
if (adjusted < 0 || adjusted >= changesets.length) {
|
||||
// Stop cursor movement when the user reaches either end.
|
||||
return;
|
||||
} else {
|
||||
var adjusted = (cursor + delta);
|
||||
if (adjusted < 0 || adjusted >= changesets.length) {
|
||||
// Stop cursor movement when the user reaches either end.
|
||||
return;
|
||||
}
|
||||
cursor = adjusted;
|
||||
|
||||
// Break the inner loop and go to the next file.
|
||||
break;
|
||||
}
|
||||
cursor = adjusted;
|
||||
}
|
||||
}
|
||||
|
||||
manager.scrollTo(selected);
|
||||
manager.focusOn(selected, extent);
|
||||
}
|
||||
|
||||
var is_haunted = false;
|
||||
|
@ -137,6 +152,19 @@ JX.behavior('differential-keyboard-navigation', function(config) {
|
|||
})
|
||||
.register();
|
||||
|
||||
new JX.KeyboardShortcut('J', 'Jump to next file.')
|
||||
.setHandler(function(manager) {
|
||||
jump(manager, 1, true);
|
||||
})
|
||||
.register();
|
||||
|
||||
new JX.KeyboardShortcut('K', 'Jump to previous file.')
|
||||
.setHandler(function(manager) {
|
||||
jump(manager, -1, true);
|
||||
})
|
||||
.register();
|
||||
|
||||
|
||||
new JX.KeyboardShortcut('z', 'Haunt / unhaunt comment panel.')
|
||||
.setHandler(haunt)
|
||||
.register();
|
||||
|
|
Loading…
Reference in a new issue