Skip to content

Commit fa72856

Browse files
authored
Override the search keyboard combination, too (#128)
1 parent 87bcc26 commit fa72856

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/scanpydoc/theme/static/scripts/rtd-sphinx-search.js

+20-17
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22
* This JS is only included when the RTD Sphinx search is active.
33
*/
44

5-
setTimeout(overrideSearchButton, 0)
6-
7-
function overrideSearchButton() {
8-
/** @type {HTMLDivElement} */
9-
const search_backdrop = document.querySelector(".search__backdrop")
10-
if (!search_backdrop) {
11-
setTimeout(overrideSearchButton, 500)
12-
return
5+
// wire up the search key combination
6+
addEventListener("keydown", ({ key, metaKey, ctrlKey }) => {
7+
if (key === "k" && (metaKey || ctrlKey)) {
8+
showSearchModal()
139
}
14-
search_backdrop.style.zIndex = "1020"
10+
})
11+
12+
// start attempting to override the search popup and to wire up the search button
13+
setTimeout(overrideSearch, 0)
1514

15+
function overrideSearch() {
16+
/** @type {HTMLDivElement} */
17+
const theme_popup = document.querySelector(".search-button__wrapper")
1618
/** @type {HTMLButtonElement} */
1719
const search_button = document.querySelector("button[aria-label='Search']")
18-
search_button.addEventListener("click", () => {
19-
showSearchModal()
20-
21-
// hide the theme’s search popup
22-
/** @type {HTMLDivElement} */
23-
const theme_popup = document.querySelector(".search-button__wrapper")
24-
theme_popup.style.display = "none"
25-
})
20+
if (!theme_popup || !search_button) {
21+
// try again later
22+
setTimeout(overrideSearch, 500)
23+
return
24+
}
25+
// Hide the pydata theme’s search popup.
26+
theme_popup.style.display = "none"
27+
// wire up the search button
28+
search_button.addEventListener("click", () => showSearchModal())
2629
}

src/scanpydoc/theme/static/styles/scanpy.css

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@ dl.citation > dt {
2121
font-size: 70% !important;
2222
}
2323

24-
/* for the search */
24+
/* Fix pydata theme search button changing size */
25+
.search-button-field {
26+
border: 0;
27+
outline: 1px solid var(--pst-color-border);
28+
}
29+
.search-button-field:hover {
30+
border: 0;
31+
outline: 2px solid var(--pst-color-link-hover);
32+
}
33+
34+
/* Make the readthedocs-sphinx-search popup adapt to the theme */
35+
/*backdrop*/
36+
html[data-theme] .search__backdrop {
37+
z-index: 1020;
38+
backdrop-filter: saturate(150%) blur(20px);
39+
}
2540
/*container*/
2641
html[data-theme] :is(.search__outer, .rtd__search__credits) {
2742
font-family: var(--pst-font-family-base);

0 commit comments

Comments
 (0)