-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add keyboard-navigation feature
#3242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
cc179ba
Add `comment-shortcuts`
yakov116 9fdce13
Work when selecting a comment
yakov116 0166489
Add comment
yakov116 d24ebd2
Add jk
yakov116 5bf6df4
Attempt to support review comment shortcuts
yakov116 27647e9
`j` `k` for reviewComments (The approval and changes requested)
yakov116 41f119b
Start feedback
yakov116 c1acf68
Apply Review Suggestions
yakov116 71d2e1b
Filter out minimized comments
yakov116 80133c5
Revert "Filter out minimized comments "
yakov116 c8500a9
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 d169fda
Filter out minimized comments
yakov116 d673891
Make hide and edit on review comments
yakov116 90a80ab
Revert "Make hide and edit on review comments"
yakov116 6ba2e6a
Duh duh duh duh. Who need the hash when you have the id!!
yakov116 3e25833
Fix edit on review comments
yakov116 0f8281a
Simplify selector
yakov116 9c6cc95
Fix my sense of direction
yakov116 a262863
Don't use popup and clean up
yakov116 50d0b23
Add description and Readme
yakov116 0f3edcb
Typescript cleanup
yakov116 3684ec0
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 f11f5c0
Apply suggestions from code review
yakov116 882ab15
Add back comment
yakov116 b3e0a39
Apply suggestions from code review
yakov116 61c6c77
Lint
yakov116 4d7fb25
Update description
yakov116 64510ee
Rename and update description
yakov116 00d2ba2
The
yakov116 90b5d4a
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 6bfce39
Drop scrollToView
yakov116 bfe60d4
Use `js-targetable-element`
yakov116 c9992f2
Apply suggestions from code review
yakov116 4be1d69
Merge remote-tracking branch 'upstream/master' into comment-shortcuts
yakov116 1c132f3
Merge branch 'master' into comment-shortcuts
yakov116 aa38357
Stay put on same index
yakov116 cb1697a
Update source/features/keyboard-navigation.tsx
yakov116 7770108
Exclude pull request reviews
yakov116 787967f
Merge branch 'master' into comment-shortcuts
fregante a07ea79
Add screenshot
fregante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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 | ||
| }); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.