utils.ts22 lines · main
| 1 | import { ICommand } from 'ui-patterns' |
| 2 | |
| 3 | import { 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 | */ |
| 11 | export 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 | } |