diff --git a/sphinx_fuma/static/fuma.js b/sphinx_fuma/static/fuma.js
index 0e4426a..42c4406 100644
--- a/sphinx_fuma/static/fuma.js
+++ b/sphinx_fuma/static/fuma.js
@@ -306,6 +306,11 @@
event.preventDefault();
window.location.href = active.href;
}
+ } else if (event.key === "Escape") {
+ // `` swallows the first Escape to clear itself, which
+ // would leave the dialog needing two presses despite the `Esc` hint.
+ event.preventDefault();
+ dialog.close();
}
});
diff --git a/sphinx_fuma/tests/test_theme.py b/sphinx_fuma/tests/test_theme.py
index 2c28f4e..81d19c3 100644
--- a/sphinx_fuma/tests/test_theme.py
+++ b/sphinx_fuma/tests/test_theme.py
@@ -217,6 +217,12 @@ def test_toc_scroll_spy_marks_every_visible_item_active(self, built):
assert 'entry.item.classList.add("fd-active")' in script
assert 'active[0].item.classList.add("fd-active")' not in script
+ def test_escape_closes_the_search_dialog_on_the_first_press(self, built):
+ script = (built / "_static" / "fuma.js").read_text()
+ # `` eats the first Escape to clear itself, so the
+ # dialog has to close on it explicitly.
+ assert 'event.key === "Escape"' in script
+
def test_tight_list_paragraphs_do_not_expand_item_spacing(self, built):
stylesheet = (built / "_static" / "fuma.css").read_text()
assert (".fd-prose ul.simple > li > p,\n.fd-prose ol.simple > li > p {\n margin: 0;\n}") in stylesheet