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

Stop gobbling escape key #12813

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Bugs fixed
file URL (user-defined base URL of an intersphinx project are left untouched
even if they end with double forward slashes).
Patch by Bénédikt Tran.
* #12811: Bail on escape key press if focus is on anything (other than a link)
gabalafou marked this conversation as resolved.
Show resolved Hide resolved

Testing
-------
Expand Down
12 changes: 3 additions & 9 deletions sphinx/themes/basic/static/doctools.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
*/
"use strict";

const BLACKLISTED_KEY_CONTROL_ELEMENTS = new Set([
"TEXTAREA",
"INPUT",
"SELECT",
"BUTTON",
]);

const _ready = (callback) => {
if (document.readyState !== "loading") {
callback();
Expand Down Expand Up @@ -111,8 +104,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
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
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;

Expand Down
5 changes: 3 additions & 2 deletions sphinx/themes/basic/static/sphinx_highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
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")) {
Expand Down