Skip to content

Commit 4c682c8

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 4c682c8

File tree

1 file changed

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

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,17 @@ aria-label="Show hidden lines"></button>';
654654
if (window.search && window.search.hasFocus()) {
655655
return;
656656
}
657+
const target = e.target;
658+
// Do not intercept shortcuts when the user is typing in an input element or code editor
659+
if (
660+
target.tagName === 'INPUT' ||
661+
target.tagName === 'TEXTAREA' ||
662+
target.isContentEditable ||
663+
target.closest && target.closest('.ace_editor')
664+
) {
665+
return;
666+
}
667+
657668
const html = document.querySelector('html');
658669

659670
function next() {

0 commit comments

Comments
 (0)