Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cc179ba
Add `comment-shortcuts`
yakov116 Jun 15, 2020
9fdce13
Work when selecting a comment
yakov116 Jun 16, 2020
0166489
Add comment
yakov116 Jun 16, 2020
d24ebd2
Add jk
yakov116 Jun 17, 2020
5bf6df4
Attempt to support review comment shortcuts
yakov116 Jun 17, 2020
27647e9
`j` `k` for reviewComments (The approval and changes requested)
yakov116 Jun 17, 2020
41f119b
Start feedback
yakov116 Jun 18, 2020
c1acf68
Apply Review Suggestions
yakov116 Jun 18, 2020
71d2e1b
Filter out minimized comments
yakov116 Jun 18, 2020
80133c5
Revert "Filter out minimized comments "
yakov116 Jun 18, 2020
c8500a9
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 Jun 18, 2020
d169fda
Filter out minimized comments
yakov116 Jun 18, 2020
d673891
Make hide and edit on review comments
yakov116 Jun 18, 2020
90a80ab
Revert "Make hide and edit on review comments"
yakov116 Jun 18, 2020
6ba2e6a
Duh duh duh duh. Who need the hash when you have the id!!
yakov116 Jun 18, 2020
3e25833
Fix edit on review comments
yakov116 Jun 18, 2020
0f8281a
Simplify selector
yakov116 Jun 19, 2020
9c6cc95
Fix my sense of direction
yakov116 Jun 19, 2020
a262863
Don't use popup and clean up
yakov116 Jun 21, 2020
50d0b23
Add description and Readme
yakov116 Jun 21, 2020
0f3edcb
Typescript cleanup
yakov116 Jun 21, 2020
3684ec0
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 Jun 21, 2020
f11f5c0
Apply suggestions from code review
yakov116 Jun 21, 2020
882ab15
Add back comment
yakov116 Jun 21, 2020
b3e0a39
Apply suggestions from code review
yakov116 Jun 21, 2020
61c6c77
Lint
yakov116 Jun 21, 2020
4d7fb25
Update description
yakov116 Jun 22, 2020
64510ee
Rename and update description
yakov116 Jun 22, 2020
00d2ba2
The
yakov116 Jun 22, 2020
90b5d4a
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 Jun 26, 2020
6bfce39
Drop scrollToView
yakov116 Jun 28, 2020
bfe60d4
Use `js-targetable-element`
yakov116 Jun 28, 2020
c9992f2
Apply suggestions from code review
yakov116 Jul 1, 2020
4be1d69
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 Jul 2, 2020
1c132f3
Merge branch 'master' into comment-shortcuts
yakov116 Jul 3, 2020
aa38357
Stay put on same index
yakov116 Jul 3, 2020
cb1697a
Update source/features/keyboard-navigation.tsx
yakov116 Jul 5, 2020
7770108
Exclude pull request reviews
yakov116 Jul 5, 2020
787967f
Merge branch 'master' into comment-shortcuts
fregante Jul 6, 2020
a07ea79
Add screenshot
fregante Jul 6, 2020
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 readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Thanks for contributing! 🦋🙌
- [](# "minimize-upload-bar") [Reduces the upload bar to a small button.](https://user-images.githubusercontent.com/55841/59802383-3d994180-92e9-11e9-835d-60de67611c30.png)
- [](# "clean-rich-text-editor") [Hides unnecessary comment field tooltips and toolbar items](https://user-images.githubusercontent.com/1402241/53629083-a4fe8900-3c47-11e9-8211-bfe2d254ffcb.png) (each one has a keyboard shortcut.)
- [](# "monospace-textareas") Use a monospace font for all textareas.
- [](# "keyboard-navigation") [Adds shortcuts to conversations and PR file lists: <kbd>j</kbd> focuses the comment/file below; <kbd>k</kbd> focuses the comment/file above.](https://user-images.githubusercontent.com/1402241/86573176-48665900-bf74-11ea-8996-a5c46cb7bdfd.gif)

<!-- Refer to style guide above. Keep this message between sections. -->

Expand Down
54 changes: 54 additions & 0 deletions source/features/keyboard-navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';
import {isEditable} from '../helpers/dom-utils';

function runShortcuts(event: KeyboardEvent): void {
if (isEditable(event.target)) {
return;
}

const focusedComment = select(':target')!;

if (['j', 'k'].includes(event.key)) {
event.preventDefault();

const items = select.all('.js-targetable-element:not([id^="pullrequestreview"]')
.filter(comment => !comment.querySelector('.minimized-comment:not(.d-none)'));
// `j` goes to the next comment, `k` goes back a comment
const direction = event.key === 'j' ? 1 : -1;

const currentIndex = items.indexOf(focusedComment);

// Start at 0 if nothing is; clamp index
const chosenCommentIndex = Math.min(
Math.max(0, currentIndex + direction),
items.length - 1
);

if (currentIndex !== chosenCommentIndex) {
// Focus comment without pushing to history
location.replace('#' + items[chosenCommentIndex].id);
}
}
}

function init(): void {
document.addEventListener('keypress', runShortcuts);
}

void features.add({
id: __filebasename,
description: 'Adds shortcuts to conversations and PR file lists: `j` focuses the comment/file below; `k` focuses the comment/file above.',
screenshot: 'https://user-images.githubusercontent.com/1402241/86573176-48665900-bf74-11ea-8996-a5c46cb7bdfd.gif',
shortcuts: {
j: 'Focus the comment/file below',
k: 'Focus the comment/file above'
}
}, {
include: [
pageDetect.hasComments
],
init
});
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ import './features/show-associated-branch-prs-on-fork';
import './features/faster-reviews';
import './features/fork-source-link-same-view';
import './features/pr-jump-to-first-non-viewed-file';
import './features/keyboard-navigation';

// Add global for easier debugging
(window as any).select = select;