Skip to content

Commit

Permalink
Implement new shortcuts:
Browse files Browse the repository at this point in the history
- "/" for Focus search bar
- "ESC" - clear highlighted text

Fixes sphinx-doc#691.

Co-authored-by: Jakob Lykke Andersen <jakobandersen@users.noreply.github.com>
  • Loading branch information
marxin and jakobandersen committed Jan 12, 2022
1 parent d741b58 commit 7a5ed92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 9 additions & 3 deletions doc/usage/theming.rst
Expand Up @@ -158,9 +158,15 @@ These themes are:
dimension string such as '70em' or '50%'. Use 'none' if you don't
want a width limit. Defaults may depend on the theme (often 800px).

- **navigation_with_keys** (true or false): Allow navigating to the
previous/next page using the keyboard's left and right arrows. Defaults to
``False``.
- **navigation_with_keys** (true or false): Allow navigating
with the following keyboard shortcuts:

- :kbd:`Left arrow`: previous page
- :kbd:`Right arrow`: next page
- :kbd:`/`: jump to Quick search
- :kbd:`Esc`: hide search matches

Defaults to ``False``.

- **globaltoc_collapse** (true or false): Only expand subsections
of the current document in ``globaltoc.html``
Expand Down
14 changes: 9 additions & 5 deletions sphinx/themes/basic/static/doctools.js
Expand Up @@ -294,21 +294,25 @@ var Documentation = {
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
&& activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
&& !event.shiftKey) {
switch (event.keyCode) {
case 37: // left
switch (event.key) {
case 'ArrowLeft':
var prevHref = $('link[rel="prev"]').prop('href');
if (prevHref) {
window.location.href = prevHref;
return false;
}
break;
case 39: // right
case 'ArrowRight':
var nextHref = $('link[rel="next"]').prop('href');
if (nextHref) {
window.location.href = nextHref;
return false;
}
break;
case '/':
$('input[name=q]').first().focus();
return false;
case 'Escape':
Documentation.hideSearchWords();
return false;
}
}
});
Expand Down

0 comments on commit 7a5ed92

Please sign in to comment.