Skip to content

Commit

Permalink
Prevent triggering hideSearchWords when closing the modal
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stsewd committed Apr 5, 2022
1 parent c95e314 commit afb6a7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions sphinx_search/static/js/rtd_sphinx_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const debounce = (func, wait) => {

/**
* Wrapper around underscorejs's template function.
*
*
* This is to make it work with new and old versions.
*/
const render_template = (template, data) => {
Expand Down Expand Up @@ -788,6 +788,14 @@ window.addEventListener("DOMContentLoaded", () => {
form.submit();
}
}

// close the search modal if the user pressed
// Escape button
if (e.keyCode === 27) {
// Avoid triggering Sphinx's 'hideSearchWords' shortcut.
e.stopPropagation();
removeSearchModal();
}
});

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

// close the search modal if the user pressed
// Escape button
document.addEventListener("keydown", e => {
if (e.keyCode === 27) {
removeSearchModal();
}
});

// open search modal if "forward slash" button is pressed
document.addEventListener("keydown", e => {
if (e.keyCode === 191 && !isModalVisible()) {
Expand Down
Loading

0 comments on commit afb6a7a

Please sign in to comment.