fix(web): prevent number-key shortcuts from hijacking input in focused editor#1810
fix(web): prevent number-key shortcuts from hijacking input in focused editor#1810D3OXY wants to merge 2 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved This is a straightforward bug fix that improves keyboard shortcut handling by checking ancestor contenteditable elements, not just the target. The unresolved review comment references incorrect code—the actual selector correctly handles all contenteditable states. You can customize Macroscope's approvability policy. Learn more. |
Addresses review feedback — the previous selector only matched contenteditable="true" exactly, missing "" and "plaintext-only". Use :not([contenteditable="false"]) to catch all valid editable states while still walking past Lexical's contenteditable="false" mention nodes.
Summary
Fixes #1794
When the AI presents a question with numbered options, a global
keydownhandler ondocumentlets users press1–9to quick-select an option. The handler guards against firing inside editable elements by checkingevent.target:The main composer is a Lexical editor (
ComposerPromptEditor), which renders a<div contenteditable="true">containing nested child elements — includingComposerMentionNodedecorations that explicitly setcontentEditable = "false". When the keydownevent.targetresolves to one of these nested children,target.isContentEditablereturnsfalse(becauseisContentEditablerespects the nearestcontenteditableattribute in the ancestor chain, including interveningcontenteditable="false"nodes). The guard fails and the number key triggers option selection instead of typing into the editor.Fix
Replace
target.isContentEditablewithtarget.closest('[contenteditable]:not([contenteditable="false"])'). This walks up the DOM tree looking for any ancestor with acontenteditableattribute that isn't explicitly"false", covering all valid editable states ("true","","plaintext-only") while still correctly skipping past Lexical'scontenteditable="false"mention decoration nodes to find the editor root.Test plan
1,2,3) — they appear as text in the editor, not select options