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/astral-letter-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

Letters outside the Basic Multilingual Plane now uppercase like other letters, so `Mod+𞤢` and `Mod+𞤀` are the same hotkey. ADLaM, which Windows has a keyboard layout for, and other scripts such as Deseret and Osage store each letter in two UTF-16 units, and `normalizeKeyName` left them lowercase. `normalizeHotkey` then gave the two spellings of one letter different canonical strings, and the recorder and labels showed the lowercase letter.
5 changes: 5 additions & 0 deletions .changeset/hebrew-pointed-letters-fall-back.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

A key that types a letter with a mark, such as `שׁ` on macOS Hebrew Shift+A, now fires the hotkey for its position, as other non-Latin letters do. The matcher treated any key value longer than one code point as a named key like `End`, so `Shift+A`, `Shift+C`, `Alt+H` and the other pointed-letter presses on the macOS Hebrew layouts fired nothing. AltGr typing such a letter now counts as typing a character too.
5 changes: 5 additions & 0 deletions .changeset/held-keys-hidden-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

Held keys now clear when the page is hidden, even when a page listener stops the `visibilitychange` event. Before, a listener on the document that called `stopPropagation()` kept the event from the key state tracker, so a key held while the user switched tabs stayed held in `getHeldKeys()` and every adapter's held-key helpers until its next keyup.
5 changes: 5 additions & 0 deletions .changeset/keyup-chord-unseen-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

A keyup chord no longer fires after another key was pressed in between when that key never reached the chord's own listener. One case is a key that a hotkey on an inner element stopped. Another is a key pressed while focus was outside the chord's target, which another hotkey's listener heard. A keyup chord also no longer fires on a later modifier release after its key was released outside its target. A press now ends at the first release of its key or one of its modifiers, and any other key press cancels it, at whichever of the hotkey manager's listeners hears that key first. An auto-repeat of the chord's key no longer restarts a press that another key cancelled.
5 changes: 5 additions & 0 deletions .changeset/recorder-latin-symbols-by-position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

The hotkey recorder now records Shift with a symbol such as the Spanish middle dot (`·`) by position, as it records Shift+/. On a Spanish keyboard, Control+Shift+3 types `·` on Windows and recorded `Mod+Shift+·`, which never fired on a Mac, where Command+Shift+3 reports `3`. It now records `Mod+Shift+[Digit3]`, which fires on both. The recorder counted `·` as a letter because it belongs to the Latin script, and the same applied to other Latin-script symbols and combining marks.
214 changes: 100 additions & 114 deletions .intent/review-state.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/reference/classes/HotkeyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Active scopes. Subscribe to show which hotkeys are suspended.
activateScope(scope, options?): () => void;
```

Defined in: [hotkey-manager.ts:670](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L670)
Defined in: [hotkey-manager.ts:672](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L672)

Activates a scope until the returned function is called. Activations are
counted, so a scope stays active until every activation is released.
Expand Down Expand Up @@ -139,7 +139,7 @@ manager.activateScope('dialog', { exclusive: { allow: ['global'] } })
destroy(): void;
```

Defined in: [hotkey-manager.ts:1817](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1817)
Defined in: [hotkey-manager.ts:1831](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1831)

Destroys the manager and removes all listeners.

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

Defined in: [hotkey-manager.ts:1749](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1749)
Defined in: [hotkey-manager.ts:1763](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1763)

Gets the number of registered hotkeys, chords and sequences.

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

Defined in: [hotkey-manager.ts:1787](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1787)
Defined in: [hotkey-manager.ts:1801](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1801)

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 @@ -205,7 +205,7 @@ True if a registration that can fire exists
isRegistered(hotkey, target?): boolean;
```

Defined in: [hotkey-manager.ts:1760](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1760)
Defined in: [hotkey-manager.ts:1774](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1774)

Checks if a specific hotkey is registered.

Expand Down Expand Up @@ -237,7 +237,7 @@ True if a matching registration exists
isScopeActive(scope?): boolean;
```

Defined in: [hotkey-manager.ts:706](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L706)
Defined in: [hotkey-manager.ts:708](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L708)

Whether hotkeys in a scope can fire: the scope is `'global'` or
activated, and either no scope is exclusive or this scope is the
Expand Down Expand Up @@ -265,7 +265,7 @@ register<T>(
): HotkeyRegistrationHandle<HotkeyOptionsFor<T>>;
```

Defined in: [hotkey-manager.ts:884](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L884)
Defined in: [hotkey-manager.ts:886](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L886)

Registers a hotkey handler and returns a handle for updating the registration.

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

Defined in: [hotkey-manager.ts:1734](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1734)
Defined in: [hotkey-manager.ts:1748](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1748)

Resets the progress of every in-progress sequence.

Expand All @@ -347,7 +347,7 @@ Resets the progress of every in-progress sequence.
static getInstance(): HotkeyManager;
```

Defined in: [hotkey-manager.ts:638](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L638)
Defined in: [hotkey-manager.ts:640](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L640)

Gets the singleton instance of HotkeyManager.

Expand All @@ -363,7 +363,7 @@ Gets the singleton instance of HotkeyManager.
static resetInstance(): void;
```

Defined in: [hotkey-manager.ts:645](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L645)
Defined in: [hotkey-manager.ts:647](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L647)

Resets the singleton instance. Useful for testing.

Expand Down
10 changes: 5 additions & 5 deletions docs/reference/classes/KeyStateTracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Use this to subscribe to state changes or access current state.
areAllKeysHeld(keys): boolean;
```

Defined in: [key-state-tracker.ts:298](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L298)
Defined in: [key-state-tracker.ts:299](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L299)

Checks if all of the given keys are currently held.

Expand All @@ -88,7 +88,7 @@ True if all of the keys are currently held
destroy(): void;
```

Defined in: [key-state-tracker.ts:305](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L305)
Defined in: [key-state-tracker.ts:306](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L306)

Destroys the tracker and removes all listeners.

Expand All @@ -104,7 +104,7 @@ Destroys the tracker and removes all listeners.
getHeldKeys(): string[];
```

Defined in: [key-state-tracker.ts:261](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L261)
Defined in: [key-state-tracker.ts:262](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L262)

Gets an array of currently held key names.

Expand All @@ -122,7 +122,7 @@ Array of key names currently being pressed
isAnyKeyHeld(keys): boolean;
```

Defined in: [key-state-tracker.ts:288](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L288)
Defined in: [key-state-tracker.ts:289](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L289)

Checks if any of the given keys are currently held.

Expand All @@ -148,7 +148,7 @@ True if any of the keys are currently held
isKeyHeld(key): boolean;
```

Defined in: [key-state-tracker.ts:275](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L275)
Defined in: [key-state-tracker.ts:276](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L276)

Checks if a specific key is currently being held.

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:1831](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1831)
Defined in: [hotkey-manager.ts:1846](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L1846)

Gets the singleton HotkeyManager instance.
Convenience function for accessing the manager.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/functions/getKeyStateTracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: getKeyStateTracker
function getKeyStateTracker(): KeyStateTracker;
```

Defined in: [key-state-tracker.ts:316](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L316)
Defined in: [key-state-tracker.ts:317](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/key-state-tracker.ts#L317)

Gets the singleton KeyStateTracker instance.
Convenience function for accessing the tracker.
Expand Down
13 changes: 11 additions & 2 deletions packages/hotkeys/src/_keyboard-event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isModifierCode, modifierAlias } from './_chord'
import { isPrintableKey, ownValue } from './_keys'
import { ownValue } from './_keys'
import { PUNCTUATION_CODE_MAP, normalizeKeyName } from './constants'
import type { NormalizedKeyboardEvent } from './key.types'
import type { HotkeyPlatform } from './platform'
Expand Down Expand Up @@ -133,6 +133,15 @@ export function codeToLogicalKey(code: string): string | undefined {
return ownValue(named, code)
}

/**
* Whether a key value is text the key typed rather than a named key such as
* `End` or `Dead`. Text can take several code points: macOS Hebrew Shift+A
* types `שׁ`, a letter with a point.
*/
export function isTypedText(key: string): boolean {
return key !== '' && !/^[A-Z][A-Za-z0-9]+$/.test(key)
}

/**
* Whether AltGr changed what a key typed, as in AltGr+Q typing `@`. False when
* AltGr is not held, or when the key typed its plain value: a named key such
Expand All @@ -145,5 +154,5 @@ export function altGraphTypedCharacter(
if (!event.altGraph) return false
// A dead key starts a composed character such as `ẽ`.
if (event.key === 'Dead') return true
return isPrintableKey(event.key) && !/^[A-Za-z0-9]$/.test(event.key)
return isTypedText(event.key) && !/^[A-Za-z0-9]$/.test(event.key)
}
12 changes: 8 additions & 4 deletions packages/hotkeys/src/_match.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
altGraphTypedCharacter,
codeToLogicalKey,
isTypedText,
macKeycapLetter,
normalizeKeyboardEvent,
} from './_keyboard-event'
Expand Down Expand Up @@ -116,7 +117,7 @@ export function matchKeyboardEvent(
platform === 'mac' &&
normalized.alt &&
(normalized.key === 'Dead' ||
(isPrintableKey(normalized.key) && !isAsciiLetter(normalized.key)))
(isTypedText(normalized.key) && !isAsciiLetter(normalized.key)))
? macKeycapLetter(event)
: undefined

Expand Down Expand Up @@ -145,7 +146,8 @@ export function matchKeyboardEvent(
/**
* Whether a key's conventional position may stand in for what it typed. Only
* output that can't name a shortcut falls back:
* - non-Latin letters and symbols, such as Russian `ы` or macOS Option's `–`
* - non-Latin letters and symbols, such as Russian `ы` or macOS Option's `–`,
* including text of several code points, such as macOS Hebrew `שׁ`
* - dead keys
* - `Unidentified` keys, except on letter positions, which layouts such as
* AZERTY rearrange, and numpad positions, whose output depends on NumLock.
Expand Down Expand Up @@ -179,13 +181,15 @@ function positionStandsIn(
!shift && !alt && (platform === 'mac' ? meta && !ctrl : ctrl && !meta)
return !zoom || !/^[-+=]$/.test(key)
}
if (key !== 'Dead' && !isPrintableKey(key)) return false
if (key === 'Dead') return true
if (!isTypedText(key)) return false
if (isAsciiLetter(key)) return false
const letterKey = code.startsWith('Key')
if (/^[!-~]$/.test(key)) {
return shift || (alt && platform === 'mac' && letterKey)
}
if (!isLatinLetter(key)) return true
// A letter with marks keeps its base letter's script
if (!isLatinLetter(Array.from(key)[0]!)) return true
if (alt && !(letterKey && ctrl && platform === 'windows')) return true
return (ctrl || meta) && !letterKey
}
6 changes: 4 additions & 2 deletions packages/hotkeys/src/_recorder-chord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ function keyName(
return isAsciiLetter(key) ? key : macKeycapLetter(event)
}
if (!typed || !key.trim()) return undefined
if (isLatinLetter(key)) return key
if (isSingleLetterKey(key)) return codeToLogicalKey(event.code)
// A Latin-script symbol such as Spanish `·` is a symbol, not a letter
if (isSingleLetterKey(key)) {
return isLatinLetter(key) ? key : codeToLogicalKey(event.code)
}
return shift ? undefined : key
}

Expand Down
7 changes: 4 additions & 3 deletions packages/hotkeys/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ export function normalizeKeyName(key: string): string {
if (key === 'ı' || key === 'ſ') return key
const upper = key.toUpperCase()
// Some Unicode letters (e.g., 'ß') uppercase to multi-character sequences
// ('SS'). Avoid changing the string length so the rest of the matching
// logic can rely on a stable single-character key value.
return upper.length === 1 ? upper : key
// ('SS'). Keep those as written, so a letter key stays one character.
// Count code points: letters outside the BMP, such as ADLaM '𞤢', take
// two UTF-16 units and uppercase to one character too.
return [...upper].length === 1 ? upper : key
}

return key === ' ' ? 'Space' : key
Expand Down
Loading
Loading