Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit afb6a7a

Browse files
committed
Prevent triggering hideSearchWords when closing the modal
Two things: - The scope of the event needs to be narrowed down (from document to just the modal). - We need to call stopPropagation so the event isn't triggered for the document object. Closes #103
1 parent c95e314 commit afb6a7a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

sphinx_search/static/js/rtd_sphinx_search.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const debounce = (func, wait) => {
4242

4343
/**
4444
* Wrapper around underscorejs's template function.
45-
*
45+
*
4646
* This is to make it work with new and old versions.
4747
*/
4848
const render_template = (template, data) => {
@@ -788,6 +788,14 @@ window.addEventListener("DOMContentLoaded", () => {
788788
form.submit();
789789
}
790790
}
791+
792+
// close the search modal if the user pressed
793+
// Escape button
794+
if (e.keyCode === 27) {
795+
// Avoid triggering Sphinx's 'hideSearchWords' shortcut.
796+
e.stopPropagation();
797+
removeSearchModal();
798+
}
791799
});
792800

793801
search_outer_wrapper.addEventListener("click", e => {
@@ -805,14 +813,6 @@ window.addEventListener("DOMContentLoaded", () => {
805813
removeSearchModal();
806814
});
807815

808-
// close the search modal if the user pressed
809-
// Escape button
810-
document.addEventListener("keydown", e => {
811-
if (e.keyCode === 27) {
812-
removeSearchModal();
813-
}
814-
});
815-
816816
// open search modal if "forward slash" button is pressed
817817
document.addEventListener("keydown", e => {
818818
if (e.keyCode === 191 && !isModalVisible()) {

0 commit comments

Comments
 (0)