utils.ts 724 B

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