Skip to content

Swarm Fix: [bug][alpha] Which Key (WhichKey): keydown with repeat === true extends the pending chord and can cancel the sequence#37721

Open
hinzwilliam52-ship-it wants to merge 1 commit intoPlatformNetwork:mainfrom
hinzwilliam52-ship-it:fix-bug-alpha-which-key-whichkey-keydown-wit-1774418265
Open

Swarm Fix: [bug][alpha] Which Key (WhichKey): keydown with repeat === true extends the pending chord and can cancel the sequence#37721
hinzwilliam52-ship-it wants to merge 1 commit intoPlatformNetwork:mainfrom
hinzwilliam52-ship-it:fix-bug-alpha-which-key-whichkey-keydown-wit-1774418265

Conversation

@hinzwilliam52-ship-it
Copy link

@hinzwilliam52-ship-it hinzwilliam52-ship-it commented Mar 25, 2026

Description

Brief description of the changes in this PR.

Related Issue

Fixes #(issue number)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Performance improvement
  • Code refactoring

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Testing

Describe the tests you ran to verify your changes.

# Example commands
cargo test
cargo clippy

Screenshots (if applicable)

Add screenshots to help explain your changes.

Summary by CodeRabbit

  • Documentation
    • Added documentation describing a fix for keyboard event handling to address issues with repeated key events interfering with keystroke sequences.

…eat === true` extends the pending chord and can cancel the sequence

Signed-off-by: hinzwilliam52-ship-it <hinzwilliam52@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

A new FIX_PROPOSAL.md document was added that describes a code fix for a keydown event handler. The proposal instructs adding a guard for event.repeat to prevent repeated key events from being appended to active keystroke sequences and causing unintended chord cancellations.

Changes

Cohort / File(s) Summary
Documentation
FIX_PROPOSAL.md
New proposal document describing a keydown handler fix with event.repeat guard logic and TypeScript implementation example.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A document hops into view,
Guarding against key events that misbehave too,
event.repeat now blocked with care,
Chords stay true, sequences fair! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main bug being fixed: keydown events with repeat === true extending pending chords in WhichKey, which aligns with the FIX_PROPOSAL.md content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@FIX_PROPOSAL.md`:
- Line 15: Add a test suite exercising the key-chord handling to verify repeated
keydown events are ignored and the sequence remains open for the next deliberate
press: write tests targeting the KeyChordHandler (or SequenceManager) and its
handleKeyDown behavior to simulate repeated keydown with event.repeat=true and
assert the sequence does not append repeats, simulate legitimate multi-key
chords to assert chords still form, and include edge-case tests (rapid repeated
presses, modifier keys, and keyup without prior keydown) to ensure no
regressions; use the public API/tests helpers that call
handleKeyDown/handleKeyUp (or processKeyEvent) and assert internal
sequence/state and emitted chord events.
- Around line 5-13: Move the raw window.addEventListener usage in
WhichKeyContext.tsx into a useEffect hook that registers a named handleKeydown
function and removes it in the cleanup return; inside handleKeydown check
event.repeat early to ignore auto-repeats, then compute the keystroke sequence
(rename the variable newPrefix to newSequence or keystrokeSequence to reflect
its purpose) and perform the existing sequence logic; ensure useEffect
dependency array includes any state/props used (e.g., currentSequence) and
replace the `// ...` placeholders with the full handler logic so the handler
works correctly in context.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7e5d06a2-bd90-43d2-b6af-736c563dc90d

📥 Commits

Reviewing files that changed from the base of the PR and between ec21e1b and fe37e2a.

📒 Files selected for processing (1)
  • FIX_PROPOSAL.md

Comment on lines +5 to +13
```typescript
// In WhichKeyContext.tsx
window.addEventListener('keydown', (event) => {
// ...
if (event.repeat) return; // Add this line to ignore repeat events
const newPrefix = [...currentSequence.keystrokes, keystroke];
// ...
});
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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.

  1. Event listener management: Using window.addEventListener directly in a React component typically requires proper setup in useEffect with cleanup to prevent memory leaks:
Recommended pattern
useEffect(() => {
  const handleKeydown = (event: KeyboardEvent) => {
    if (event.repeat) return;
    // ... rest of handler
  };
  
  window.addEventListener('keydown', handleKeydown);
  return () => window.removeEventListener('keydown', handleKeydown);
}, [/* dependencies */]);
  1. Misleading variable name: newPrefix on line 10 represents a keystroke sequence, not a prefix, which is confusing terminology.

  2. Incomplete snippet: The // ... placeholders make it difficult to verify the fix works correctly in context.

Note: event.repeat is 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
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` around lines 5 - 13, Move the raw window.addEventListener
usage in WhichKeyContext.tsx into a useEffect hook that registers a named
handleKeydown function and removes it in the cleanup return; inside
handleKeydown check event.repeat early to ignore auto-repeats, then compute the
keystroke sequence (rename the variable newPrefix to newSequence or
keystrokeSequence to reflect its purpose) and perform the existing sequence
logic; ensure useEffect dependency array includes any state/props used (e.g.,
currentSequence) and replace the `// ...` placeholders with the full handler
logic so the handler works correctly in context.

});
```

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. No newline at end of file
Copy link

Choose a reason for hiding this comment

The 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:

  • Repeated keydown events are properly ignored
  • The sequence remains open for the next deliberate key press
  • The fix doesn't prevent legitimate multi-key chords from working
  • Edge cases are handled correctly

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
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` at line 15, Add a test suite exercising the key-chord
handling to verify repeated keydown events are ignored and the sequence remains
open for the next deliberate press: write tests targeting the KeyChordHandler
(or SequenceManager) and its handleKeyDown behavior to simulate repeated keydown
with event.repeat=true and assert the sequence does not append repeats, simulate
legitimate multi-key chords to assert chords still form, and include edge-case
tests (rapid repeated presses, modifier keys, and keyup without prior keydown)
to ensure no regressions; use the public API/tests helpers that call
handleKeyDown/handleKeyUp (or processKeyEvent) and assert internal
sequence/state and emitted chord events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant