fix: prevent '?' shortcut from intercepting input in code editors#3065
fix: prevent '?' shortcut from intercepting input in code editors#3065kartik-py12 wants to merge 1 commit intorust-lang:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an early guard to the global keydown handler so the ? help shortcut (and other navigation shortcuts handled there) won’t intercept keystrokes while the user is typing in editable UI (inputs/textareas/contenteditable/Ace editor), addressing the embedded editor “can’t type ?” regression.
Changes:
- Guard
chapterNavigationkeydown handling when the event target is an editable element. - Treat Ace editor DOM (
.ace_editor) as editable to avoid intercepting typing in playground editors.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const target = e.target; | ||
|
|
||
| // Do not intercept shortcuts when the user is typing in an input element or code editor | ||
| if ( | ||
| target.tagName === 'INPUT' || | ||
| target.tagName === 'TEXTAREA' || |
There was a problem hiding this comment.
The newly added guard contains trailing whitespace (including the blank line after const target = e.target; and spaces after ||), which violates the repo’s ESLint no-trailing-spaces rule and will fail npm run lint. Please remove the trailing spaces so the file passes lint.
| target.isContentEditable || | ||
| (target.closest && target.closest('.ace_editor')) | ||
| ) { |
There was a problem hiding this comment.
(target.closest && target.closest('.ace_editor')) has unnecessary parentheses; with no-extra-parens enabled in ESLint, this is likely to be reported as a lint error. Consider removing the wrapping parentheses while keeping the short-circuit guard.
4c682c8 to
ffab758
Compare
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 rust-lang#3064
ffab758 to
39301c4
Compare
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 and rust-lang/rust-by-example#1984