Fix useHotkeySequence resets progress when modifier key is pressed before a key combo e.g. zA (Vim-like hotkeys) #74
main fromrefs/pull/74/head·merged by KevinVandy 🎯 Changes#
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm run test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
Bug Fixes
- Modifier-only key presses (e.g., Shift) no longer reset or disrupt multi-step hotkey sequences, so Vim-style combos behave reliably.
Tests
- Added tests verifying modifier-key handling and that incorrect intermediate keys still break sequences.
Documentation
- Updated sequence-related docs to match current sources.
New Features
- Added demo/example entries showcasing chained Shift+letter sequences.
Chores
- Added a changeset recording the patch release.
- 1
klaskow(GitHub profile, opens in a new tab) changed the title
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/hotkeys/tests/sequence-manager.test.ts (1)
516-549: Good coverage for the reported bug; add one regression case for modifier-only sequence steps.Please add a case like
['Shift', 'C']to ensure modifier-only key steps still progress (and don’t get swallowed globally).🧪 Suggested test addition
describe('modifier key handling', () => { + it('should allow modifier-only step when explicitly part of the sequence', () => { + const manager = SequenceManager.getInstance() + const callback = vi.fn() + + manager.register(['Shift', 'C'], callback) + + document.dispatchEvent( + new KeyboardEvent('keydown', { key: 'Shift', bubbles: true }), + ) + document.dispatchEvent( + new KeyboardEvent('keydown', { key: 'c', bubbles: true }), + ) + + expect(callback).toHaveBeenCalledTimes(1) + }) + it('should not reset sequence when modifier key is pressed between steps', () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/hotkeys/tests/sequence-manager.test.ts` around lines 516 - 549, Add a regression test that registers a sequence containing a modifier-only step (e.g., SequenceManager.getInstance().register(['Shift', 'C'], callback)) and asserts the sequence still progresses when the modifier key is pressed alone then the non-modifier step is pressed; specifically, simulate dispatching a 'Shift' keydown (modifier-only step) then a 'c' keydown with shiftKey: true and assert callback was called once, and include a negative case where an unrelated key between steps prevents the callback (use dispatchKey helper and the existing describe 'modifier key handling' block to place the test near register and dispatchKey usages).🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Inline comments: In @.changeset/lovely-boats-grin.md: - Line 2: The release type in the changeset entry "'@tanstack/hotkeys': minor" is too high for a bug-fix; update that entry to use "patch" instead of "minor" so the changeset reads "'@tanstack/hotkeys': patch" to reflect a patch-level release. --- Nitpick comments: In `@packages/hotkeys/tests/sequence-manager.test.ts`: - Around line 516-549: Add a regression test that registers a sequence containing a modifier-only step (e.g., SequenceManager.getInstance().register(['Shift', 'C'], callback)) and asserts the sequence still progresses when the modifier key is pressed alone then the non-modifier step is pressed; specifically, simulate dispatching a 'Shift' keydown (modifier-only step) then a 'c' keydown with shiftKey: true and assert callback was called once, and include a negative case where an unrelated key between steps prevents the callback (use dispatchKey helper and the existing describe 'modifier key handling' block to place the test near register and dispatchKey usages).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
cd9a2baa-24e2-491b-86c8-78878623dfb4📥 Commits
Reviewing files that changed from the base of the PR and between bbbb4ed0e133627acf636ceae1b3899c286bf7e8 and f61a53b573f3263d6fab20589321b1a884429029.
📒 Files selected for processing (3)
.changeset/lovely-boats-grin.mdpackages/hotkeys/src/sequence-manager.tspackages/hotkeys/tests/sequence-manager.test.ts
.changeset/lovely-boats-grin.md line 2OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,2 @@1+---2+'@tanstack/hotkeys': minor⚠️ Potential issue | 🟡 Minor
Release type seems too high for a pure bug fix.
This looks like a patch-level fix; consider lowering
minortopatchunless there’s an intentional feature-level contract change.📦 Suggested change
-'@tanstack/hotkeys': minor +'@tanstack/hotkeys': patch📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change2-'@tanstack/hotkeys': minor2+'@tanstack/hotkeys': patch🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.changeset/lovely-boats-grin.md at line 2, The release type in the changeset entry "'@tanstack/hotkeys': minor" is too high for a bug-fix; update that entry to use "patch" instead of "minor" so the changeset reads "'@tanstack/hotkeys': patch" to reflect a patch-level release.✅ Addressed in commit be00482
@tanstack/angular-hotkeys
npm i https://pkg.pr.new/@tanstack/angular-hotkeys@74@tanstack/hotkeys
npm i https://pkg.pr.new/@tanstack/hotkeys@74@tanstack/hotkeys-devtools
npm i https://pkg.pr.new/@tanstack/hotkeys-devtools@74@tanstack/preact-hotkeys
npm i https://pkg.pr.new/@tanstack/preact-hotkeys@74@tanstack/preact-hotkeys-devtools
npm i https://pkg.pr.new/@tanstack/preact-hotkeys-devtools@74@tanstack/react-hotkeys
npm i https://pkg.pr.new/@tanstack/react-hotkeys@74@tanstack/react-hotkeys-devtools
npm i https://pkg.pr.new/@tanstack/react-hotkeys-devtools@74@tanstack/solid-hotkeys
npm i https://pkg.pr.new/@tanstack/solid-hotkeys@74@tanstack/solid-hotkeys-devtools
npm i https://pkg.pr.new/@tanstack/solid-hotkeys-devtools@74@tanstack/svelte-hotkeys
npm i https://pkg.pr.new/@tanstack/svelte-hotkeys@74@tanstack/vue-hotkeys
npm i https://pkg.pr.new/@tanstack/vue-hotkeys@74@tanstack/vue-hotkeys-devtools
npm i https://pkg.pr.new/@tanstack/vue-hotkeys-devtools@74commit:
22ed15cKevinVandy approved these changes
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Inline comments: In `@examples/angular/injectHotkeySequence/src/app/app.component.html`: - Around line 117-119: The `<pre>` snippet contains unescaped '>' characters in the arrow functions which violates HTMLHint's spec-char-escape rule; update the two occurrences inside the snippet that call injectHotkeySequence (the lines referencing injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord()) and injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething())) by replacing each '>' in the arrow `=>` with `>` so the HTML is properly escaped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
afeaf62e-4d16-4d87-a5b7-2d7cccb15828📥 Commits
Reviewing files that changed from the base of the PR and between 6296c176cc102c6eacf60c91f32267ccae68dd03 and 22ed15c69c177f711fcbbb0677c73d0ce0c3be64.
📒 Files selected for processing (7)
examples/angular/injectHotkeySequence/src/app/app.component.htmlexamples/angular/injectHotkeySequence/src/app/app.component.tsexamples/preact/useHotkeySequence/src/index.tsxexamples/react/useHotkeySequence/src/index.tsxexamples/solid/createHotkeySequence/src/index.tsxexamples/svelte/create-hotkey-sequence/src/App.svelteexamples/vue/useHotkeySequence/src/App.vue
✅ Files skipped from review due to trivial changes (1)
- examples/angular/injectHotkeySequence/src/app/app.component.ts
@@ -89,4 +114,6 @@89114 {{ '{' }} timeout: 1500 {{ '}' }}90115 )9111692-injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord())</pre117+injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord())118+119+injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething())</pre⚠️ Potential issue | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
git ls-files | grep -E "examples/angular/injectHotkeySequence/src/app/app.component.html"Repository: TanStack/hotkeys
Length of output: 124
🏁 Script executed:
if [ -f "examples/angular/injectHotkeySequence/src/app/app.component.html" ]; then wc -l "examples/angular/injectHotkeySequence/src/app/app.component.html" fiRepository: TanStack/hotkeys
Length of output: 128
🏁 Script executed:
if [ -f "examples/angular/injectHotkeySequence/src/app/app.component.html" ]; then sed -n '110,125p' "examples/angular/injectHotkeySequence/src/app/app.component.html" fiRepository: TanStack/hotkeys
Length of output: 456
🏁 Script executed:
find . -name ".htmlhintrc" -o -name "htmlhint*" -o -name ".htmlhintignore" 2>/dev/null | head -20Repository: TanStack/hotkeys
Length of output: 73
🏁 Script executed:
rg "htmlhint\|spec-char-escape" --type json --type js --type yaml -A 3 | head -50Repository: TanStack/hotkeys
Length of output: 42
🏁 Script executed:
cat .htmlhintrcRepository: TanStack/hotkeys
Length of output: 213
Escape
>in the<pre>usage snippet to satisfy HTMLHint linting.The code contains unescaped
>characters within=>operators inside<pre>tags, which violates thespec-char-escaperule enabled in.htmlhintrc. Replace>with>in both lines:Suggested fix
-injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord()) +injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord()) -injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething()) +injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething())📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change117-injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord())118-119-injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething())</pre117+injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord())118+119+injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething())</pre🧰 Tools
🪛 HTMLHint (1.9.2)
[error] 117-117: Special characters must be escaped : [ > ].
(spec-char-escape)
[error] 119-119: Special characters must be escaped : [ > ].
(spec-char-escape)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/angular/injectHotkeySequence/src/app/app.component.html` around lines 117 - 119, The `<pre>` snippet contains unescaped '>' characters in the arrow functions which violates HTMLHint's spec-char-escape rule; update the two occurrences inside the snippet that call injectHotkeySequence (the lines referencing injectHotkeySequence(['C', 'I', 'W'], () => changeInnerWord()) and injectHotkeySequence(['Shift+R', 'Shift+T'], () => doSomething())) by replacing each '>' in the arrow `=>` with `>` so the HTML is properly escaped.KevinVandy merged thisa3aa4f3
KevinVandy closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
SequenceManager now ignores modifier-only KeyboardEvents during sequence processing, preventing modifier presses (e.g., Shift) between steps from advancing or resetting combo progress. Changes include implementation update, tests, docs reference adjustments, examples, and a changeset entry.
Changes#
packages/hotkeys/src/sequence-manager.ts#processTargetEventto skip processing whenisModifierKey(event)is true; importedisModifierKey.packages/hotkeys/tests/sequence-manager.test.tsdocs/reference/classes/SequenceManager.md,docs/reference/functions/createSequenceMatcher.md,docs/reference/functions/getSequenceManager.mdexamples/.../useHotkeySequence/src/index.tsx,examples/.../createHotkeySequence/src/index.tsx,examples/angular/.../app.component.html,examples/angular/.../app.component.ts,examples/react/.../index.tsx,examples/preact/.../index.tsx,examples/solid/.../index.tsx,examples/svelte/.../App.svelte,examples/vue/.../App.vue['Shift+R', 'Shift+T']across frameworks; UI text and usage snippets updated to note that modifier-only presses do not reset progress..changeset/lovely-boats-grin.mduseHotkeySequence/sequence processing.Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem#
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)#
✅ Passed checks (1 passed)
✨ 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.
❤️ Share