diff --git a/CHANGES.rst b/CHANGES.rst index 6cef031159d..eb04a10cd67 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,5 +18,8 @@ Features added Bugs fixed ---------- +* #12813: Stop gobbling escape key + Patch by Gabriel Fouasnon. + Testing ------- diff --git a/sphinx/themes/basic/static/doctools.js b/sphinx/themes/basic/static/doctools.js index 0398ebb9f03..e01b53c4d78 100644 --- a/sphinx/themes/basic/static/doctools.js +++ b/sphinx/themes/basic/static/doctools.js @@ -3,13 +3,6 @@ */ "use strict"; -const BLACKLISTED_KEY_CONTROL_ELEMENTS = new Set([ - "TEXTAREA", - "INPUT", - "SELECT", - "BUTTON", -]); - const _ready = (callback) => { if (document.readyState !== "loading") { callback(); @@ -104,8 +97,9 @@ const Documentation = { return; document.addEventListener("keydown", (event) => { - // bail for input elements - if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; + // bail if browser focus is on anything but a link (or the body) + const focusEl = document.activeElement; + if (focusEl && (focusEl !== document.body || focusEl.tagName !== "A")) return; // bail with special keys if (event.altKey || event.ctrlKey || event.metaKey) return; diff --git a/sphinx/themes/basic/static/sphinx_highlight.js b/sphinx/themes/basic/static/sphinx_highlight.js index 8a96c69a194..1bd7b34d71e 100644 --- a/sphinx/themes/basic/static/sphinx_highlight.js +++ b/sphinx/themes/basic/static/sphinx_highlight.js @@ -133,8 +133,9 @@ const SphinxHighlight = { if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS) return; document.addEventListener("keydown", (event) => { - // bail for input elements - if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return; + // bail if browser focus is on anything but a link (or the body) + const focusEl = document.activeElement; + if (focusEl && (focusEl !== document.body || focusEl.tagName !== "A")) return; // bail with special keys if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return; if (DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS && (event.key === "Escape")) {