summaryrefslogtreecommitdiff
path: root/source/features/pagination-hotkey.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'source/features/pagination-hotkey.tsx')
-rw-r--r--source/features/pagination-hotkey.tsx50
1 files changed, 50 insertions, 0 deletions
diff --git a/source/features/pagination-hotkey.tsx b/source/features/pagination-hotkey.tsx
new file mode 100644
index 00000000..77862e7e
--- /dev/null
+++ b/source/features/pagination-hotkey.tsx
@@ -0,0 +1,50 @@
+import select from 'select-dom';
+import * as pageDetect from 'github-url-detection';
+
+import features from '.';
+
+const nextPageButtonSelectors = [
+ 'a.next_page', // Issue/PR list, Search
+ '.paginate-container.BtnGroup > :last-child', // Notifications
+ '.paginate-container > .BtnGroup > :last-child', // Commits
+ '.paginate-container > .pagination > :last-child', // Releases
+ '.prh-commit > .BtnGroup > :last-child', // PR Commits
+];
+
+const previousPageButtonSelectors = [
+ 'a.previous_page', // Issue/PR list, Search
+ '.paginate-container.BtnGroup > :first-child', // Notifications
+ '.paginate-container > .BtnGroup > :first-child', // Commits
+ '.paginate-container > .pagination > :first-child', // Releases
+ '.prh-commit > .BtnGroup > :first-child', // PR Commits
+];
+
+function init(): void {
+ const createNextPageButton = select(nextPageButtonSelectors);
+ if (createNextPageButton) {
+ createNextPageButton.dataset.hotkey = 'ArrowRight';
+ }
+
+ const createPreviousPageButton = select(previousPageButtonSelectors);
+ if (createPreviousPageButton) {
+ createPreviousPageButton.dataset.hotkey = 'ArrowLeft';
+ }
+}
+
+void features.add(__filebasename, {
+ shortcuts: {
+ '→': 'Go to the next page',
+ '←': 'Go to the previous page',
+ },
+ // TODO: enable for isDiscussionList after #4695 is fixed
+ include: [
+ pageDetect.isConversationList,
+ pageDetect.isGlobalSearchResults,
+ pageDetect.isLabelList,
+ pageDetect.isNotifications,
+ pageDetect.isRepoCommitList,
+ pageDetect.isPRCommit,
+ pageDetect.isUserProfileRepoTab,
+ ],
+ init,
+});