-
Notifications
You must be signed in to change notification settings - Fork 27
Swarm Fix: [bug][alpha] Which Key (WhichKey): keydown with repeat === true extends the pending chord and can cancel the sequence
#37721
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| To fix the issue, you need to add a check for `event.repeat` in the `keydown` event listener. If `event.repeat` is `true`, you should ignore the event and not append the keystroke to the sequence. | ||
|
|
||
| Here is the exact code fix: | ||
|
|
||
| ```typescript | ||
| // In WhichKeyContext.tsx | ||
| window.addEventListener('keydown', (event) => { | ||
| // ... | ||
| if (event.repeat) return; // Add this line to ignore repeat events | ||
| const newPrefix = [...currentSequence.keystrokes, keystroke]; | ||
| // ... | ||
| }); | ||
| ``` | ||
|
|
||
| This will prevent the repeat events from appending to the sequence and canceling the chord. Instead, the sequence will remain open for the next deliberate key press. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add tests to verify the expected behavior. The proposal describes the expected behavior but doesn't include any tests to verify that:
Would you like me to generate a test suite that covers these scenarios, or open an issue to track adding comprehensive tests for this fix? 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
MDN KeyboardEvent repeat property documentation and browser support💡 Result:
The MDN documentation for the KeyboardEvent.repeat property states that it is a read-only boolean property of the KeyboardEvent interface. It returns true if the given key is being held down such that it is automatically repeating. Syntax: var repeat = event.repeat; Value: A boolean value. Specification: Defined in UI Events # dom-keyboardevent-repeat. Browser support (as of 2026, based on CanIUse data): - Chrome: Full support since version 32 (partial before), full in recent versions (137+). - Firefox: Full support since 28. - Safari: Full support since 10.1 (desktop), 10.3 (iOS). - Edge: Full support since 79 (and IE 9-11 supported). - Opera: Full support since recent versions. - Mobile browsers generally follow desktop counterparts, with full support in recent versions. The feature has broad support across modern browsers since around 2015-2017, with no support in very old versions (e.g., Chrome <32, Firefox <28). MDN notes it as baseline compatible since 2025 for latest browsers.
Citations:
The proposed code snippet has several concerns.
window.addEventListenerdirectly in a React component typically requires proper setup inuseEffectwith cleanup to prevent memory leaks:Recommended pattern
Misleading variable name:
newPrefixon line 10 represents a keystroke sequence, not a prefix, which is confusing terminology.Incomplete snippet: The
// ...placeholders make it difficult to verify the fix works correctly in context.Note:
event.repeatis a valid and well-supported property for detecting auto-repeated key presses across all modern browsers (Chrome 32+, Firefox 28+, Safari 10.1+, Edge 79+).🤖 Prompt for AI Agents