Skip to content

Commit e4e192a

Browse files
committed
Implement new shortcuts:
- "s" and "/" for Focus search bar - "h" - clear highlighted text Fixes #691.
1 parent c66b3ad commit e4e192a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

doc/usage/theming.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ These themes are:
155155
want a width limit. Defaults may depend on the theme (often 800px).
156156

157157
- **navigation_with_keys** (true or false): Allow navigating to the
158-
previous/next page using the keyboard's left and right arrows. Defaults to
159-
``False``.
158+
previous/next page using the keyboard's left and right arrows.
159+
Apart from that, 's' and '/' jumps to Quick search and 'c'
160+
hides search matches. Defaults to ``False``.
160161

161162
- **globaltoc_collapse** (true or false): Only expand subsections
162163
of the current document in ``globaltoc.html``

sphinx/themes/basic/static/doctools.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,21 +294,28 @@ var Documentation = {
294294
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
295295
&& activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
296296
&& !event.shiftKey) {
297-
switch (event.keyCode) {
298-
case 37: // left
297+
switch (event.key) {
298+
case 'ArrowLeft':
299299
var prevHref = $('link[rel="prev"]').prop('href');
300300
if (prevHref) {
301301
window.location.href = prevHref;
302302
return false;
303303
}
304-
break;
305-
case 39: // right
304+
case 'ArrowRight':
306305
var nextHref = $('link[rel="next"]').prop('href');
307306
if (nextHref) {
308307
window.location.href = nextHref;
309308
return false;
310309
}
311-
break;
310+
case '/':
311+
case 's':
312+
$('input[name=q]').focus();
313+
return false;
314+
case 'h':
315+
newurl = window.location.href.replace(new RegExp('\\?highlight=[^#]*'), '');
316+
history.pushState({}, null, newurl);
317+
Documentation.hideSearchWords();
318+
return false;
312319
}
313320
}
314321
});

0 commit comments

Comments
 (0)