Skip to content

Commit 6e09439

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

File tree

5 files changed

+50
-48
lines changed

5 files changed

+50
-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: 43 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

@@ -266,6 +267,13 @@ var Documentation = {
266267
window.history.replaceState({}, '', url);
267268
},
268269

270+
/**
271+
* helper function to focus on search bar
272+
*/
273+
focusSearchBar : function() {
274+
$('input[name=q]').first().focus();
275+
},
276+
269277
/**
270278
* make the url absolute
271279
*/
@@ -290,50 +298,52 @@ var Documentation = {
290298
initOnKeyListeners: function() {
291299
// only install a listener if it is really needed
292300
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
293-
!DOCUMENTATION_OPTIONS.SEARCH_WITH_KEYS &&
294-
!DOCUMENTATION_OPTIONS.REMOVE_HIGHLIGHT_WITH_KEYS)
301+
!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
295302
return;
303+
296304
$(document).keydown(function(event) {
297305
var activeElementType = document.activeElement.tagName;
298306
// don't navigate when in search box, textarea, dropdown or button
299307
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
300308
&& 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)
309+
if (event.altKey || event.ctrlKey || event.metaKey)
310+
return;
311+
312+
if (!event.shiftKey) {
313+
switch (event.key) {
314+
case 'ArrowLeft':
315+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
316+
break;
317+
var prevHref = $('link[rel="prev"]').prop('href');
318+
if (prevHref) {
319+
window.location.href = prevHref;
320+
return false;
321+
}
305322
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)
323+
case 'ArrowRight':
324+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
325+
break;
326+
var nextHref = $('link[rel="next"]').prop('href');
327+
if (nextHref) {
328+
window.location.href = nextHref;
329+
return false;
330+
}
314331
break;
315-
var nextHref = $('link[rel="next"]').prop('href');
316-
if (nextHref) {
317-
window.location.href = nextHref;
332+
case 'Escape':
333+
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
334+
break;
335+
Documentation.hideSearchWords();
318336
return false;
319-
}
320-
break;
321-
case 'Escape':
322-
if (!DOCUMENTATION_OPTIONS.REMOVE_HIGHLIGHT_WITH_KEYS)
323-
break;
324-
Documentation.hideSearchWords();
325-
return false;
326337
}
327338
}
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-
}
339+
340+
// some keyboard layouts may need Shift to get /
341+
switch (event.key) {
342+
case '/':
343+
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
344+
break;
345+
Documentation.focusSearchBar();
346+
return false;
337347
}
338348
}
339349
});

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)