From ef5491a72f66c437ff2ac5f33364e162e1813be2 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Mon, 15 Jan 2024 11:18:55 +0100 Subject: [PATCH] Fix search interactions (#132) --- .../theme/static/scripts/rtd-sphinx-search.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/scanpydoc/theme/static/scripts/rtd-sphinx-search.js b/src/scanpydoc/theme/static/scripts/rtd-sphinx-search.js index 4083fc9..e60531b 100644 --- a/src/scanpydoc/theme/static/scripts/rtd-sphinx-search.js +++ b/src/scanpydoc/theme/static/scripts/rtd-sphinx-search.js @@ -3,11 +3,19 @@ */ // wire up the search key combination -addEventListener("keydown", ({ key, metaKey, ctrlKey }) => { - if (key === "k" && (metaKey || ctrlKey)) { - showSearchModal() - } -}) +addEventListener( + "keydown", + ({ key, metaKey, ctrlKey }) => { + if (key === "k" && (metaKey || ctrlKey)) { + if (isModalVisible()) { + removeSearchModal() + } else { + showSearchModal() + } + } + }, + { passive: true }, +) // start attempting to override the search popup and to wire up the search button setTimeout(overrideSearch, 0)