utils.ts22 lines · main
1import { ICommand } from 'ui-patterns'
2
3import { SHORTCUT_IDS } from './registry'
4
5/**
6 * Shared orderer for the Cmd+K "Shortcuts" section. Keeps the "Show all
7 * keyboard shortcuts" entry pinned to the bottom regardless of registration
8 * order; everything else is order-stable. Exported so `useDynamicShortcut`
9 * can share the same ordering behavior.
10 */
11export const orderShortcutCommands = (
12 commands: ICommand[],
13 commandsToInsert: ICommand[]
14): ICommand[] => {
15 const mergedCommands = [...commands, ...commandsToInsert]
16
17 return mergedCommands.sort((a, b) => {
18 if (a.id === SHORTCUT_IDS.SHORTCUTS_OPEN_REFERENCE) return 1
19 if (b.id === SHORTCUT_IDS.SHORTCUTS_OPEN_REFERENCE) return -1
20 return 0
21 })
22}