mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9337 from marxin/new-shortcuts
Implement new search shortcuts.
This commit is contained in:
commit
799385f555
3
CHANGES
3
CHANGES
@ -16,6 +16,9 @@ Features added
|
|||||||
* #10125: extlinks: Improve suggestion message for a reference having title
|
* #10125: extlinks: Improve suggestion message for a reference having title
|
||||||
* #9494, #9456: html search: Add a config variable
|
* #9494, #9456: html search: Add a config variable
|
||||||
:confval:`html_show_search_summary` to enable/disable the search summaries
|
:confval:`html_show_search_summary` to enable/disable the search summaries
|
||||||
|
* #9337: HTML theme, add option ``enable_search_shortcuts`` that enables :kbd:'/' as
|
||||||
|
a Quick search shortcut and :kbd:`Esc` shortcut that
|
||||||
|
removes search highlighting.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -158,9 +158,18 @@ These themes are:
|
|||||||
dimension string such as '70em' or '50%'. Use 'none' if you don't
|
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).
|
want a width limit. Defaults may depend on the theme (often 800px).
|
||||||
|
|
||||||
- **navigation_with_keys** (true or false): Allow navigating to the
|
- **navigation_with_keys** (true or false): Allow navigating
|
||||||
previous/next page using the keyboard's left and right arrows. Defaults to
|
with the following keyboard shortcuts:
|
||||||
``False``.
|
|
||||||
|
- :kbd:`Left arrow`: previous page
|
||||||
|
- :kbd:`Right arrow`: next page
|
||||||
|
|
||||||
|
Defaults to ``False``.
|
||||||
|
|
||||||
|
- **enable_search_shortcuts** (true or false): Allow jumping to the search box
|
||||||
|
with :kbd:`/` and allow removal of search highlighting with :kbd:`Esc`.
|
||||||
|
|
||||||
|
Defaults to ``True``.
|
||||||
|
|
||||||
- **globaltoc_collapse** (true or false): Only expand subsections
|
- **globaltoc_collapse** (true or false): Only expand subsections
|
||||||
of the current document in ``globaltoc.html``
|
of the current document in ``globaltoc.html``
|
||||||
|
@ -154,9 +154,7 @@ var Documentation = {
|
|||||||
this.fixFirefoxAnchorBug();
|
this.fixFirefoxAnchorBug();
|
||||||
this.highlightSearchWords();
|
this.highlightSearchWords();
|
||||||
this.initIndexTable();
|
this.initIndexTable();
|
||||||
if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) {
|
this.initOnKeyListeners();
|
||||||
this.initOnKeyListeners();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -269,6 +267,13 @@ var Documentation = {
|
|||||||
window.history.replaceState({}, '', url);
|
window.history.replaceState({}, '', url);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper function to focus on search bar
|
||||||
|
*/
|
||||||
|
focusSearchBar : function() {
|
||||||
|
$('input[name=q]').first().focus();
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make the url absolute
|
* make the url absolute
|
||||||
*/
|
*/
|
||||||
@ -291,27 +296,54 @@ var Documentation = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
initOnKeyListeners: function() {
|
initOnKeyListeners: function() {
|
||||||
|
// only install a listener if it is really needed
|
||||||
|
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
|
||||||
|
!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
|
||||||
|
return;
|
||||||
|
|
||||||
$(document).keydown(function(event) {
|
$(document).keydown(function(event) {
|
||||||
var activeElementType = document.activeElement.tagName;
|
var activeElementType = document.activeElement.tagName;
|
||||||
// don't navigate when in search box, textarea, dropdown or button
|
// don't navigate when in search box, textarea, dropdown or button
|
||||||
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
|
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
|
||||||
&& activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
|
&& activeElementType !== 'BUTTON') {
|
||||||
&& !event.shiftKey) {
|
if (event.altKey || event.ctrlKey || event.metaKey)
|
||||||
switch (event.keyCode) {
|
return;
|
||||||
case 37: // left
|
|
||||||
var prevHref = $('link[rel="prev"]').prop('href');
|
if (!event.shiftKey) {
|
||||||
if (prevHref) {
|
switch (event.key) {
|
||||||
window.location.href = prevHref;
|
case 'ArrowLeft':
|
||||||
return false;
|
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
|
||||||
}
|
break;
|
||||||
break;
|
var prevHref = $('link[rel="prev"]').prop('href');
|
||||||
case 39: // right
|
if (prevHref) {
|
||||||
var nextHref = $('link[rel="next"]').prop('href');
|
window.location.href = prevHref;
|
||||||
if (nextHref) {
|
return false;
|
||||||
window.location.href = nextHref;
|
}
|
||||||
return false;
|
break;
|
||||||
}
|
case 'ArrowRight':
|
||||||
break;
|
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
|
||||||
|
break;
|
||||||
|
var nextHref = $('link[rel="next"]').prop('href');
|
||||||
|
if (nextHref) {
|
||||||
|
window.location.href = nextHref;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'Escape':
|
||||||
|
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
|
||||||
|
break;
|
||||||
|
Documentation.hideSearchWords();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// some keyboard layouts may need Shift to get /
|
||||||
|
switch (event.key) {
|
||||||
|
case '/':
|
||||||
|
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
|
||||||
|
break;
|
||||||
|
Documentation.focusSearchBar();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -9,5 +9,6 @@ var DOCUMENTATION_OPTIONS = {
|
|||||||
HAS_SOURCE: {{ has_source|lower }},
|
HAS_SOURCE: {{ has_source|lower }},
|
||||||
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}',
|
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}',
|
||||||
NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}},
|
NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}},
|
||||||
SHOW_SEARCH_SUMMARY: {{ 'true' if show_search_summary else 'false' }}
|
SHOW_SEARCH_SUMMARY: {{ 'true' if show_search_summary else 'false' }},
|
||||||
|
ENABLE_SEARCH_SHORTCUTS: {{ 'true' if enable_search_shortcuts|tobool else 'true'}},
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@ sidebarwidth = 230
|
|||||||
body_min_width = 450
|
body_min_width = 450
|
||||||
body_max_width = 800
|
body_max_width = 800
|
||||||
navigation_with_keys = False
|
navigation_with_keys = False
|
||||||
|
enable_search_shortcuts = True
|
||||||
globaltoc_collapse = true
|
globaltoc_collapse = true
|
||||||
globaltoc_includehidden = false
|
globaltoc_includehidden = false
|
||||||
globaltoc_maxdepth =
|
globaltoc_maxdepth =
|
||||||
|
Loading…
Reference in New Issue
Block a user