Skip to content

Commit 39301c4

Browse files
committed
fix: prevent '?' shortcut from intercepting input in code editors
This adds a guard to the global keydown listener in book.js so that the '?' shortcut does not intercept keypresses when the user is focused inside an input, textarea, or Ace editor block. Fixes #3064
1 parent 05fbc5d commit 39301c4

File tree

1 file changed

+10
-0
lines changed
  • crates/mdbook-html/front-end/js

1 file changed

+10
-0
lines changed

crates/mdbook-html/front-end/js/book.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ aria-label="Show hidden lines"></button>';
654654
if (window.search && window.search.hasFocus()) {
655655
return;
656656
}
657+
657658
const html = document.querySelector('html');
658659

659660
function next() {
@@ -707,6 +708,15 @@ aria-label="Show hidden lines"></button>';
707708
// Usually needs the Shift key to be pressed
708709
switch (e.key) {
709710
case '?':
711+
const active = document.activeElement;
712+
if (active &&
713+
(
714+
active.tagName === 'INPUT' ||
715+
active.tagName === 'TEXTAREA' ||
716+
active.isContentEditable
717+
)) {
718+
return;
719+
}
710720
e.preventDefault();
711721
showHelp();
712722
break;

0 commit comments

Comments
 (0)