Skip to content

Commit 160df9a

Browse files
committed
Change theme value to enable_search_shortcuts.
And rework javascript shortcut handling.
1 parent c18be2e commit 160df9a

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

CHANGES

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ Features added
4949
references for readability with standalone readers
5050
* #9822 (and #9062), add new Intersphinx role :rst:role:`external` for explict
5151
lookup in the external projects, without resolving to the local project.
52-
* #9337: HTML theme, add option ``search_with_keys`` that enables :kbd:'/' as
53-
a Quick search shortcut.
54-
Add option ``remove_highlight_with_keys`` that enables :kbd:`Esc` shortcut
55-
that removes search highlighting.
52+
* #9337: HTML theme, add option ``enable_search_shortcuts`` that enables :kbd:'/' as
53+
a Quick search shortcut and :kbd:`Esc` shortcut that
54+
removes search highlighting.
5655

5756
Bugs fixed
5857
----------

doc/usage/theming.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,8 @@ These themes are:
166166

167167
Defaults to ``False``.
168168

169-
- **search_with_keys** (true or false): Allow jumping to the search box
170-
with :kbd:`/`.
171-
172-
Defaults to ``True``.
173-
174-
- **remove_highlight_with_keys** (true or false): Allow removal of search
175-
highlighting with :kbd:`Esc`.
169+
- **enable_search_shortcuts** (true or false): Allow jumping to the search box
170+
with :kbd:`/` and allow removal of search highlighting with :kbd:`Esc`.
176171

177172
Defaults to ``True``.
178173

sphinx/themes/basic/static/doctools.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ var Documentation = {
153153
init : function() {
154154
this.fixFirefoxAnchorBug();
155155
this.highlightSearchWords();
156+
this.initIndexTable();
156157
this.initOnKeyListeners();
157158
},
158159

@@ -290,50 +291,52 @@ var Documentation = {
290291
initOnKeyListeners: function() {
291292
// only install a listener if it is really needed
292293
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
293-
!DOCUMENTATION_OPTIONS.SEARCH_WITH_KEYS &&
294-
!DOCUMENTATION_OPTIONS.REMOVE_HIGHLIGHT_WITH_KEYS)
294+
!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
295295
return;
296+
296297
$(document).keydown(function(event) {
297298
var activeElementType = document.activeElement.tagName;
298299
// don't navigate when in search box, textarea, dropdown or button
299300
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
300301
&& activeElementType !== 'BUTTON') {
301-
if (!event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
302-
switch (event.key) {
303-
case 'ArrowLeft':
304-
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
302+
if (event.altKey || event.ctrlKey || event.metaKey)
303+
return;
304+
305+
if (!event.shiftKey) {
306+
switch (event.key) {
307+
case 'ArrowLeft':
308+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
309+
break;
310+
var prevHref = $('link[rel="prev"]').prop('href');
311+
if (prevHref) {
312+
window.location.href = prevHref;
313+
return false;
314+
}
305315
break;
306-
var prevHref = $('link[rel="prev"]').prop('href');
307-
if (prevHref) {
308-
window.location.href = prevHref;
309-
return false;
310-
}
311-
break;
312-
case 'ArrowRight':
313-
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
316+
case 'ArrowRight':
317+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
318+
break;
319+
var nextHref = $('link[rel="next"]').prop('href');
320+
if (nextHref) {
321+
window.location.href = nextHref;
322+
return false;
323+
}
314324
break;
315-
var nextHref = $('link[rel="next"]').prop('href');
316-
if (nextHref) {
317-
window.location.href = nextHref;
325+
case 'Escape':
326+
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
327+
break;
328+
Documentation.hideSearchWords();
318329
return false;
319-
}
320-
break;
321-
case 'Escape':
322-
if (!DOCUMENTATION_OPTIONS.REMOVE_HIGHLIGHT_WITH_KEYS)
323-
break;
324-
Documentation.hideSearchWords();
325-
return false;
326330
}
327331
}
328-
if (!event.altKey && !event.ctrlKey && !event.metaKey) {
329-
// some keyboard layouts need Shift to get /
330-
switch (event.key) {
331-
case '/':
332-
if (!DOCUMENTATION_OPTIONS.SEARCH_WITH_KEYS)
333-
break;
334-
$('input[name=q]').first().focus();
335-
return false;
336-
}
332+
333+
// some keyboard layouts may need Shift to get /
334+
switch (event.key) {
335+
case '/':
336+
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
337+
break;
338+
$('input[name=q]').first().focus();
339+
return false;
337340
}
338341
}
339342
});

sphinx/themes/basic/static/documentation_options.js_t

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ var DOCUMENTATION_OPTIONS = {
99
HAS_SOURCE: {{ has_source|lower }},
1010
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}',
1111
NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}},
12-
SEARCH_WITH_KEYS: {{ 'true' if theme_search_with_keys|tobool else 'true'}},
13-
REMOVE_HIGHLIGHT_WITH_KEYS: {{ 'true' if theme_remove_highlight_with_keys|tobool else 'true'}}
12+
ENABLE_SEARCH_SHORTCUTS: {{ 'true' if enable_search_shortcuts|tobool else 'true'}},
1413
};

sphinx/themes/basic/theme.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ sidebarwidth = 230
1010
body_min_width = 450
1111
body_max_width = 800
1212
navigation_with_keys = False
13-
search_with_keys = True
14-
remove_highlight_with_keys = True
13+
enable_search_shortcuts = True
1514
globaltoc_collapse = true
1615
globaltoc_includehidden = false
1716
globaltoc_maxdepth =

0 commit comments

Comments
 (0)