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 Mar 7, 2022
1 parent ef1c782 commit 88012e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 88012e9

Please sign in to comment.