Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent triggering hideSearchWords when closing the modal #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/requirements.txt
@@ -1,4 +1,4 @@
sphinx==4.4.0
sphinx==4.5.0
sphinx-prompt==1.5.0
sphinx-tabs==3.2.0
sphinx-rtd-theme==1.0.0
Expand Down
18 changes: 9 additions & 9 deletions sphinx_search/static/js/rtd_sphinx_search.js
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();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but now the modal isn't closed if the panel lost the focus (and hideSearchWords is triggered :/), was able to reproduce by clicking on the "white area" of the modal, but clicking on the search box gains the focus and escape works again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you'll need to add an event listener for something other than the input box. This key code event is only on the search_outer_input element, where you likely also want to listen on search_outer.

});

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