mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-29 04:32:57 +00:00
Allow users to clear and restore shortcut bindings, persist the explicit unassigned state, and keep shortcut displays and actions aligned with the binding that fires. Includes focused unit coverage and desktop renderer Playwright coverage.
29 lines
1006 B
TypeScript
29 lines
1006 B
TypeScript
import type { ShortcutKey } from "@/utils/format-shortcut";
|
|
|
|
/**
|
|
* The combos a `Shortcut` should render, or `null` when it should render
|
|
* nothing at all.
|
|
*
|
|
* `keys={[]}` is the trap this exists to close: it wraps to `[[]]`, whose first
|
|
* element is an empty array — truthy — so a first-element check waves it
|
|
* through and an empty badge pill renders. A shortcut with no keys, whether the
|
|
* user unassigned it or it ships without a default combo, has to produce no
|
|
* element at all.
|
|
*/
|
|
export function normalizeDisplayChord(
|
|
chord?: ShortcutKey[][],
|
|
keys?: ShortcutKey[],
|
|
): ShortcutKey[][] | null {
|
|
const combos = chord ?? (keys ? [keys] : []);
|
|
if (combos.length === 0) {
|
|
return null;
|
|
}
|
|
// A chord with an empty step cannot be drawn honestly: rendering it would
|
|
// show a blank pill, and dropping the step would advertise a shorter
|
|
// sequence than the one that actually fires.
|
|
if (combos.some((combo) => combo.length === 0)) {
|
|
return null;
|
|
}
|
|
return combos;
|
|
}
|