Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ document.addEventListener('DOMContentLoaded', () => {

if (pageDetect.isPR() || pageDetect.isIssue()) {
markUnread.setup();
enableIssuesPrevNext.setup();
}
});
}
Expand Down
29 changes: 29 additions & 0 deletions extension/issues-prevnext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* globals utils */

'use strict';

const PREV_KEYCODE = 37;
const NEXT_KEYCODE = 39;

window.enableIssuesPrevNext = (() => {
const handler = ({keyCode, target}) => {
// just go to prev/next issue based on current issue number
if ((keyCode === PREV_KEYCODE || keyCode === NEXT_KEYCODE) && target.nodeName !== 'INPUT' && target.nodeName !== 'TEXTAREA') {
Copy link
Contributor

@DrewML DrewML Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check may be too generic. For users that prefer to navigate with keyboard shortcuts instead of the mouse, those keys are used to scroll left/right. (this was suggested in #152 by other contributors, though, so maybe I'm in the minority).

const uri = location.href.replace(/\/issues\/(\d+)\/?$/, function(match, current) {
const offset = (keyCode === PREV_KEYCODE) ? -1 : 1;
const num = Math.max(1, parseInt(current, 10) + offset);
return `/issues/${num}`;
});
document.location = uri;
}
};

return {
setup: () => {
window.addEventListener('keyup', handler);
Copy link
Contributor

@DrewML DrewML Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These events should be removed when a user navigates away from the issues section. GitHub doesn't do full page reloads for a lot of navigation in the app, so this handler could execute on unexpected pages.

},
destroy: () => {
window.removeEventListener('keyup', handler);
}
};
})();
3 changes: 2 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"show-names.js",
"content.js",
"add-blame-parent-links.js",
"mark-unread.js"
"mark-unread.js",
"issues-prevnext.js"
]
}
]
Expand Down