Skip to content

Commit

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

Fixes #691.
  • Loading branch information
marxin committed Aug 12, 2021
1 parent c66b3ad commit 6f36876
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc/usage/theming.rst
Expand Up @@ -155,8 +155,9 @@ These themes are:
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``.
previous/next page using the keyboard's left and right arrows.
Apart from that, 's' and '/' jumps to Quick search and 'h'
hides search matches. Defaults to ``False``.

- **globaltoc_collapse** (true or false): Only expand subsections
of the current document in ``globaltoc.html``
Expand Down
17 changes: 12 additions & 5 deletions sphinx/themes/basic/static/doctools.js
Expand Up @@ -264,6 +264,8 @@ var Documentation = {
hideSearchWords : function() {
$('#searchbox .highlight-link').fadeOut(300);
$('span.highlighted').removeClass('highlighted');
newurl = window.location.href.replace(new RegExp('\\?highlight=[^#]*'), '');
history.pushState({}, null, newurl);
},

/**
Expand Down Expand Up @@ -294,21 +296,26 @@ 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 '/':
case 's':
$('input[name=q]').focus();
return false;
case 'h':
Documentation.hideSearchWords();
return false;
}
}
});
Expand Down

0 comments on commit 6f36876

Please sign in to comment.