Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/match-keys-first.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

Key presses cost less when many hotkeys are registered. With 100 hotkeys on the document, a key press takes about a fifth of the time it did in Chromium, and about a seventh with 1,000. The manager now reads each key event once for all hotkeys, compares the key before it checks a hotkey's state, and no longer copies its list of hotkeys several times per event. Which hotkeys fire is unchanged.
80 changes: 43 additions & 37 deletions .intent/review-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
]
},
"skill:packages/hotkeys/skills/hotkeys-core/SKILL.md": {
"fingerprint": "44f31755a95d2a7183ace483a9edbbe5af61f9e4ecbc4575f154e5e8cc62da84",
"fingerprint": "672f5476818c7f708e1460cdab16e72baec662026e25b798941b4f5b986004ed",
"snapshot": {
"docs/framework/react/guides/hotkeys-provider-and-scopes.md": "57039ef29571e18c058ea77d104140e33c9b7fbda7de561c4d77247a47a566ce",
"docs/framework/react/guides/hotkeys.md": "14f8f41603cb30d71ae69a527b6f3d58c9ade5d9e1530818c56e4dd32bfcd7c0",
Expand All @@ -104,7 +104,7 @@
"packages/hotkeys/skills/hotkeys-core/SKILL.md": "7b3987dbd1ff362ca2c243d7f091cfdfa76718ab004f0ca1940f37ebdde4def8",
"packages/hotkeys/skills/hotkeys-core/references/scopes.md": "1139da465c06e76ee1d489cb14fc3ce952011666b67f64855846805c241c2108",
"packages/hotkeys/skills/hotkeys-core/references/testing.md": "c2957eaac34ca431832069156504cf7434dcb96d5227bcb7cbb2129dc8e979bd",
"packages/hotkeys/src/hotkey-manager.ts": "11d5c43a649bc98992db7e838171fd1be79d45009f344766626285ea347fecc4",
"packages/hotkeys/src/hotkey-manager.ts": "004a43f4e82e78ece8aabecb61b43f45934c452c3f59f4a615c2622407fd933d",
"packages/hotkeys/src/match.ts": "80c3c08023591cb2444aa2adbd5249ad7e2aeffd3dc4f8c529f142aab9141aaa",
"packages/react-hotkeys/tests/skills/editor-shortcuts/editor-shortcuts.test.tsx": "73411ec7c25652244ed31ad4120880dfc08d6e10af959bef04d2df5360769fde",
"packages/react-hotkeys/tests/skills/editor-shortcuts/fixture.tsx": "613a833bb6412b600925deb4009d16cfbfe7afa9a5dc0b82d1a39b8da8c0230b",
Expand All @@ -116,11 +116,11 @@
"packages/react-hotkeys/tests/skills/editor-shortcuts/solution.tsx": "ec81379bf0e3a9950222cf8525f82f8abefeb6b46339550fd3a8622e61bf4f0d",
"packages/react-hotkeys/tests/skills/editor-shortcuts/task.md": "9610d80e7add59f0433cbf210562ff8c481dc2c14371ce31c00a329d9ff1fedf"
},
"head": "243d225e0291f8b364274b43249cec722dad8b17",
"head": "59cceb805ee2c2e9ee86fc8280182f83f44f08f9",
"outcome": "no-change",
"reason": "The skill describes matching and the Shift-with-a-symbol type rule, which still hold. The recorder now keeps Mac symbols reported only with Shift, and custom uncased keys go with Shift; neither changes what the skill tells agents to write.",
"reason": "Performance refactor of key event dispatch in hotkey-manager.ts, _match.ts and _target-listeners.ts: the event is read once per pass, keys are compared before a chord's state is checked, and per-event copies of the registration id sets are gone. No public API, option, default or firing rule changed, so the hotkeys-core guidance and the three planning documents stay accurate. Checked by 2,237 core unit tests, unit tests of all 19 packages, 333 browser tests in Chromium, Firefox and WebKit, and 248 keyboard layout tests in Docker.",
"evidence": [
"packages/hotkeys/skills/hotkeys-core/SKILL.md Modifiers match exactly bullet; packages/hotkeys/src/_recorder-chord.ts MAC_COMMAND_SHIFTED_SYMBOLS; key.types.ts ShiftableKey."
"Changed: packages/hotkeys/src/hotkey-manager.ts at 59cceb805ee2c2e9ee86fc8280182f83f44f08f9"
]
},
"skill:packages/lit-hotkeys/skills/lit-hotkeys/SKILL.md": {
Expand Down Expand Up @@ -273,7 +273,7 @@
]
},
"planning:_artifacts": {
"fingerprint": "e6aaa7ca53136bbae36814647651d0900fd7fa2851520da59f4527c24387b51c",
"fingerprint": "ff033d23c5e7da8f65d133075ce029d90e3c493c15fe6246d70558de47e952d7",
"snapshot": {
"_artifacts/domain_map.yaml": "81f47610362c2c3891c750e50a75b13b461f6304005af9bd7d51a801386bc098",
"_artifacts/skill_spec.md": "d77ed3bb07efdd8a167ae1b5ab08a23e1deba52832ad1bf1ea72625deb25082c",
Expand Down Expand Up @@ -336,7 +336,7 @@
"packages/hotkeys/skills/hotkeys-core/references/testing.md": "c2957eaac34ca431832069156504cf7434dcb96d5227bcb7cbb2129dc8e979bd",
"packages/hotkeys/src/app-hotkeys.ts": "4620760d8409fb78a94319b6e52ca1a00c625121e29006fa1cef057fdeafa937",
"packages/hotkeys/src/conflicts.ts": "3c8628500aee3e7ba14ec78411b5f5398fd66cbc00359ffdf227a81729a76fe5",
"packages/hotkeys/src/hotkey-manager.ts": "11d5c43a649bc98992db7e838171fd1be79d45009f344766626285ea347fecc4",
"packages/hotkeys/src/hotkey-manager.ts": "004a43f4e82e78ece8aabecb61b43f45934c452c3f59f4a615c2622407fd933d",
"packages/hotkeys/src/hotkey-recorder.ts": "55c0e764812a4dd3907c915939904613fc3b7b66d967e09e5bedb754b143056a",
"packages/hotkeys/src/match.ts": "80c3c08023591cb2444aa2adbd5249ad7e2aeffd3dc4f8c529f142aab9141aaa",
"packages/lit-hotkeys/skills/lit-hotkeys/SKILL.md": "326b0a1ddd9579c65389e755d5a2e0a69512ef7f91aca21bda7db9c0ddb51521",
Expand Down Expand Up @@ -404,11 +404,11 @@
"packages/vue-hotkeys/src/useHotkeyRecorder.ts": "f9090de677350d72ae3e1732eab11e5b89b5cf00021f2cc5e88d2fe3f2fb743d",
"packages/vue-hotkeys/src/useHotkeys.ts": "219ded7bd27e250567817a9e74cb6c0032a58c1da6a6be81e820f4a67ab6c8c7"
},
"head": "243d225e0291f8b364274b43249cec722dad8b17",
"head": "59cceb805ee2c2e9ee86fc8280182f83f44f08f9",
"outcome": "no-change",
"reason": "No new domain or reference is needed: both changes refine existing recorder and type rules.",
"reason": "Performance refactor of key event dispatch in hotkey-manager.ts, _match.ts and _target-listeners.ts: the event is read once per pass, keys are compared before a chord's state is checked, and per-event copies of the registration id sets are gone. No public API, option, default or firing rule changed, so the hotkeys-core guidance and the three planning documents stay accurate. Checked by 2,237 core unit tests, unit tests of all 19 packages, 333 browser tests in Chromium, Firefox and WebKit, and 248 keyboard layout tests in Docker.",
"evidence": [
"_artifacts/domain_map.yaml already covers recording and hotkey string types."
"Changed: packages/hotkeys/src/hotkey-manager.ts at 59cceb805ee2c2e9ee86fc8280182f83f44f08f9"
]
},
"source:.changeset/intent-skills.md": {
Expand Down Expand Up @@ -664,24 +664,28 @@
]
},
"source:docs/reference/classes/HotkeyManager.md": {
"fingerprint": "b736e804ca87593fb73865ff759cec35b0e882ae80173774d368f27d7b0076a5",
"fingerprint": "9fc36c41935243987969a8883a0d53ef2ee9da799b04ab1d57810dc521e321d1",
"snapshot": {
"docs/reference/classes/HotkeyManager.md": "04225c4292b8d315af3aa7384b3024bdd0ac96c60de55615b847c919b273c579"
"docs/reference/classes/HotkeyManager.md": "26deec98a47b37b2e7c0e14cfff1424b6bd82ddda125b72ad4fc16415f94a556"
},
"head": "f026c8ab12658715ab51ace277262ea6e38eddc2",
"outcome": "out-of-scope",
"reason": "Generated reference docs, sidebar config, unit tests, or e2e specs for the Shift-with-symbol type rule, the SymbolKey rename, the recorder change, and formatForDisplay(\"Mod\"); no skill guidance depends on them.",
"evidence": ["No skill references this file"]
"head": "d9063cefbc8bf789116bc165c6ad91d9bf1f78e2",
"outcome": "no-change",
"reason": "The autofix job regenerated two reference pages. All 7 changed lines are 'Defined in' links whose hotkey-manager.ts line numbers moved by 13; no documented API, signature or description changed.",
"evidence": [
"Changed: docs/reference/classes/HotkeyManager.md at d9063cefbc8bf789116bc165c6ad91d9bf1f78e2"
]
},
"source:docs/reference/functions/getHotkeyManager.md": {
"fingerprint": "068e8543b8a799f27f911aa3457a7cbb2eb19a0533a39be647e0e91a3bf7c3b5",
"fingerprint": "04d140f54bf584b22f14e1cbf4669e46d1c6c834ab7251fec17cd988b10863bf",
"snapshot": {
"docs/reference/functions/getHotkeyManager.md": "071c823e94184cb47fc5f514df5540061ce62b1b7b57f513c7d59d2bad7957eb"
"docs/reference/functions/getHotkeyManager.md": "f8f7b70a932532b6f4b9295a8ee8cf54fd516657ee258f8ae2d8d43f8d04fc22"
},
"head": "f026c8ab12658715ab51ace277262ea6e38eddc2",
"outcome": "out-of-scope",
"reason": "Generated reference docs, sidebar config, unit tests, or e2e specs for the Shift-with-symbol type rule, the SymbolKey rename, the recorder change, and formatForDisplay(\"Mod\"); no skill guidance depends on them.",
"evidence": ["No skill references this file"]
"head": "d9063cefbc8bf789116bc165c6ad91d9bf1f78e2",
"outcome": "no-change",
"reason": "The autofix job regenerated two reference pages. All 7 changed lines are 'Defined in' links whose hotkey-manager.ts line numbers moved by 13; no documented API, signature or description changed.",
"evidence": [
"Changed: docs/reference/functions/getHotkeyManager.md at d9063cefbc8bf789116bc165c6ad91d9bf1f78e2"
]
},
"source:examples/alpine/kitchen-sink/index.html": {
"fingerprint": "e576c33ec891eff09138d3a05b3c29fffc60c984b7f4e88a1dca3848a899cdc5",
Expand Down Expand Up @@ -4368,15 +4372,15 @@
]
},
"source:packages/hotkeys/tests/input-detection.test.ts": {
"fingerprint": "817e5c72fbdf2ba89dbf58003e7662466b06a716d35f042e6177092ba9e975ad",
"fingerprint": "391c24c5dfdac3431d64ccfefcaeef67527d84734537256f5bfd394b2598b893",
"snapshot": {
"packages/hotkeys/tests/input-detection.test.ts": "ae2a0b301305485d9c2d0049ca7231e91da2a159e1c05231b44f9fd50d80ff73"
"packages/hotkeys/tests/input-detection.test.ts": "cffa83151964ec2c8b094caa96529f9ed987df88b098d4384d6e49ec2a771d0d"
},
"head": "ce272666d8aae7bebafc02b184b29fcd2e853125",
"head": "856f644ea45ad94419f9ec6205ebe2594aa41842",
"outcome": "no-change",
"reason": "Combined test-coverage branch: tests, test setup, e2e suites, CI workflows and tooling config only. Regenerated reference pages only reorder a union type or change a node_modules path. No API or guidance change.",
"reason": "Test-only change in input-detection.test.ts: a second case pins that the bubble-phase hotkey is skipped when no earlier hotkey skips text fields. No source or guidance changed.",
"evidence": [
"Changed: packages/hotkeys/tests/input-detection.test.ts at ce272666d8aae7bebafc02b184b29fcd2e853125"
"Changed: packages/hotkeys/tests/input-detection.test.ts at 856f644ea45ad94419f9ec6205ebe2594aa41842"
]
},
"source:packages/hotkeys/tests/registration-and-target.test.ts": {
Expand Down Expand Up @@ -4410,14 +4414,16 @@
"evidence": ["e2e/support/x11.ts"]
},
"source:packages/hotkeys/src/_match.ts": {
"fingerprint": "0995379b09a5bd847d3a736e1cba492f5c653b08dabc9cff7bcfabde880b4dab",
"fingerprint": "2aa643cbb50bb1096fda63734caf196e9e03adad4011165ddae9fdcaf3eb7c2a",
"snapshot": {
"packages/hotkeys/src/_match.ts": "dc54a8a388f697eb9cf1c4d3fe281786a845cbd992c4a66330be98e494694be9"
"packages/hotkeys/src/_match.ts": "7e20de30e5a143aad3f2766182c17093d714e8285bb897419d155bb389f51e7f"
},
"head": "cd1c66aab538ccac294e72ee36ae4466fa9b2d2b",
"head": "59cceb805ee2c2e9ee86fc8280182f83f44f08f9",
"outcome": "no-change",
"reason": "Internal change: the private constants move or the character-key classification behind suspendCharacterKeys. The core skill covers the public behavior.",
"evidence": ["packages/hotkeys/skills/hotkeys-core/SKILL.md"]
"reason": "Performance refactor of key event dispatch in hotkey-manager.ts, _match.ts and _target-listeners.ts: the event is read once per pass, keys are compared before a chord's state is checked, and per-event copies of the registration id sets are gone. No public API, option, default or firing rule changed, so the hotkeys-core guidance and the three planning documents stay accurate. Checked by 2,236 core unit tests, unit tests of all 19 packages, 333 browser tests in Chromium, Firefox and WebKit, and 248 keyboard layout tests in Docker.",
"evidence": [
"Changed: packages/hotkeys/src/_match.ts at 59cceb805ee2c2e9ee86fc8280182f83f44f08f9"
]
},
"source:packages/hotkeys/tests/match.test.ts": {
"fingerprint": "29930787adfc4098826fa994f10f2f118b0f65e77ca0e48a5f2cfaaf8be07946",
Expand Down Expand Up @@ -7394,15 +7400,15 @@
"evidence": ["packages/vue-hotkeys/tests/unset-values.test.ts"]
},
"source:packages/hotkeys/src/_target-listeners.ts": {
"fingerprint": "8a51e16771a1ce1f0315a0f1a5c897086284d5979bcffc72418e9c29eff236e7",
"fingerprint": "9c715beaa3aa22febb49eab64adf27d5e920f21d21e7cf7b948ece4c74118258",
"snapshot": {
"packages/hotkeys/src/_target-listeners.ts": "39a0ca154b1dc5bfe6907108e1ca1603388b8a3153820eaa41bd033240aea5bc"
"packages/hotkeys/src/_target-listeners.ts": "d44c8263f113cba31d801e6c3e6fa50ed43ccded15394b6fb62191394272fc4f"
},
"head": "a3fc3ae3a058631dfe821a04edf4cf0cce49fb0a",
"head": "59cceb805ee2c2e9ee86fc8280182f83f44f08f9",
"outcome": "no-change",
"reason": "Recorder target now cancels when its window closes; element hotkeys follow their element on focus. Skills don't cover the recorder target or listener placement, so no guidance changes",
"reason": "Performance refactor of key event dispatch in hotkey-manager.ts, _match.ts and _target-listeners.ts: the event is read once per pass, keys are compared before a chord's state is checked, and per-event copies of the registration id sets are gone. No public API, option, default or firing rule changed, so the hotkeys-core guidance and the three planning documents stay accurate. Checked by 2,237 core unit tests, unit tests of all 19 packages, 333 browser tests in Chromium, Firefox and WebKit, and 248 keyboard layout tests in Docker.",
"evidence": [
"Changed: packages/hotkeys/src/_target-listeners.ts at a3fc3ae3a058631dfe821a04edf4cf0cce49fb0a"
"Changed: packages/hotkeys/src/_target-listeners.ts at 59cceb805ee2c2e9ee86fc8280182f83f44f08f9"
]
},
"source:packages/hotkeys/tests/capture.test.ts": {
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/classes/HotkeyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ manager.activateScope('dialog', { exclusive: { allow: ['global'] } })
destroy(): void;
```

Defined in: [hotkey-manager.ts:2274](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2274)
Defined in: [hotkey-manager.ts:2287](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2287)

Destroys the manager and removes all listeners.

Expand All @@ -129,7 +129,7 @@ Destroys the manager and removes all listeners.
getRegistrationCount(): number;
```

Defined in: [hotkey-manager.ts:2206](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2206)
Defined in: [hotkey-manager.ts:2219](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2219)

Gets the number of registered hotkeys, chords and sequences.

Expand All @@ -145,7 +145,7 @@ Gets the number of registered hotkeys, chords and sequences.
hasActiveRegistration(hotkey): boolean;
```

Defined in: [hotkey-manager.ts:2244](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2244)
Defined in: [hotkey-manager.ts:2257](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2257)

Checks whether a hotkey can fire now: at least one registration is
enabled, in an active scope, and listening where key presses go. A
Expand Down Expand Up @@ -179,7 +179,7 @@ True if a registration that can fire exists
isRegistered(hotkey, target?): boolean;
```

Defined in: [hotkey-manager.ts:2217](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2217)
Defined in: [hotkey-manager.ts:2230](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2230)

Checks if a specific hotkey is registered.

Expand Down Expand Up @@ -305,7 +305,7 @@ handle.unregister()
resetSequenceProgress(): void;
```

Defined in: [hotkey-manager.ts:2191](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2191)
Defined in: [hotkey-manager.ts:2204](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2204)

Resets the progress of every in-progress sequence.

Expand Down Expand Up @@ -357,7 +357,7 @@ resume()
trigger(id, event?): boolean;
```

Defined in: [hotkey-manager.ts:2179](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2179)
Defined in: [hotkey-manager.ts:2192](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2192)

Runs a registration's callback without a key press, as for a command
palette entry or a devtools button. The callback gets the same context as
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/functions/getHotkeyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: getHotkeyManager
function getHotkeyManager(): HotkeyManager;
```

Defined in: [hotkey-manager.ts:2295](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2295)
Defined in: [hotkey-manager.ts:2308](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L2308)

Gets the singleton HotkeyManager instance.
Convenience function for accessing the manager.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"name": "HotkeyManager",
"path": "packages/hotkeys/dist/index.js",
"import": "{ getHotkeyManager }",
"limit": "9.25 KB"
"limit": "9.3 KB"
},
{
"name": "HotkeyRecorder",
Expand Down Expand Up @@ -129,7 +129,7 @@
"react",
"react-dom"
],
"limit": "12 KB"
"limit": "12.1 KB"
},
{
"name": "Preact useHotkey",
Expand Down Expand Up @@ -197,7 +197,7 @@
"ignore": [
"alpinejs"
],
"limit": "13 KB"
"limit": "13.1 KB"
},
{
"name": "Alpine hotkeyDirective",
Expand Down
Loading
Loading