-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add vim key bindings for navigation #3072
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -718,6 +718,7 @@ | |
| } | ||
|
|
||
| switch (e.key) { | ||
| case 'l': | ||
| case 'ArrowRight': | ||
| e.preventDefault(); | ||
| if (html.dir === 'rtl') { | ||
|
|
@@ -726,6 +727,7 @@ | |
| next(); | ||
| } | ||
| break; | ||
| case 'h': | ||
| case 'ArrowLeft': | ||
| e.preventDefault(); | ||
| if (html.dir === 'rtl') { | ||
|
|
@@ -734,6 +736,22 @@ | |
| prev(); | ||
| } | ||
| break; | ||
| case 'j': | ||
| e.preventDefault(); | ||
| window.scrollBy({ top: 80, behavior: 'smooth' }); | ||
| break; | ||
| case 'k': | ||
| e.preventDefault(); | ||
| window.scrollBy({ top: -80, behavior: 'smooth' }); | ||
| break; | ||
| case 'd': | ||
| e.preventDefault(); | ||
| window.scrollBy({ top: window.innerHeight, behavior: 'smooth' }); | ||
| break; | ||
| case 'u': | ||
| e.preventDefault(); | ||
| window.scrollBy({ top: -window.innerHeight, behavior: 'smooth' }); | ||
| break; | ||
|
Comment on lines
+739
to
+754
|
||
| } | ||
| }); | ||
| })(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -67,7 +67,8 @@ | |||||
| <div id="mdbook-help-popup"> | ||||||
| <h2 class="mdbook-help-title">Keyboard shortcuts</h2> | ||||||
| <div> | ||||||
| <p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p> | ||||||
| <p>Press <kbd>←</kbd>/<kbd>→</kbd> or <kbd>h</kbd>/<kbd>l</kbd> to navigate between chapters</p> | ||||||
| <p>Press <kbd>j</kbd>/<kbd>k</kbd> or <kbd>d</kbd>/<kbd>u</kbd> to scroll the page up and down</p> | ||||||
|
||||||
| <p>Press <kbd>j</kbd>/<kbd>k</kbd> or <kbd>d</kbd>/<kbd>u</kbd> to scroll the page up and down</p> | |
| <p>Press <kbd>j</kbd>/<kbd>k</kbd> to scroll a small amount, or <kbd>d</kbd>/<kbd>u</kbd> to scroll roughly one page</p> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,8 @@ The **arrow buttons** at the bottom of the page can be used to navigate to the p | |||||
|
|
||||||
| The **left and right arrow keys** on the keyboard can be used to navigate to the previous or the next chapter. | ||||||
|
|
||||||
| Additionally, Vim-style key bindings (<kbd>H</kbd>, <kbd>J</kbd>, <kbd>K</kbd>, <kbd>L</kbd>, <kbd>D</kbd> and <kbd>U</kbd>) can be used for navigation. | ||||||
|
||||||
| Additionally, Vim-style key bindings (<kbd>H</kbd>, <kbd>J</kbd>, <kbd>K</kbd>, <kbd>L</kbd>, <kbd>D</kbd> and <kbd>U</kbd>) can be used for navigation. | |
| Additionally, Vim-style key bindings can be used: <kbd>h</kbd> and <kbd>l</kbd> navigate to the previous and next chapter, while <kbd>j</kbd>, <kbd>k</kbd>, <kbd>d</kbd>, and <kbd>u</kbd> scroll the current page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These scroll actions always use
behavior: 'smooth'. For users who prefer reduced motion, this can be an accessibility issue. Consider detectingprefers-reduced-motion: reduceand usingbehavior: 'auto'(or omittingbehavior) when reduced motion is requested.