( commands: CommandDefinition[], recentCommands: Record<string, number> )
| 482 | }) |
| 483 | |
| 484 | export const orderCommandsForMenu = ( |
| 485 | commands: CommandDefinition[], |
| 486 | recentCommands: Record<string, number> |
| 487 | ): CommandDefinition[] => |
| 488 | [...commands].sort((leftCommand, rightCommand) => { |
| 489 | const leftTimestamp = recentCommands[leftCommand.key] ?? 0 |
| 490 | const rightTimestamp = recentCommands[rightCommand.key] ?? 0 |
| 491 | |
| 492 | if (leftTimestamp !== rightTimestamp) { |
| 493 | return rightTimestamp - leftTimestamp |
| 494 | } |
| 495 | |
| 496 | const leftDefaultOrder = DEFAULT_ORDER_BY_KEY.get(leftCommand.key) |
| 497 | const rightDefaultOrder = DEFAULT_ORDER_BY_KEY.get(rightCommand.key) |
| 498 | |
| 499 | if (leftDefaultOrder !== undefined && rightDefaultOrder !== undefined) { |
| 500 | return leftDefaultOrder - rightDefaultOrder |
| 501 | } |
| 502 | |
| 503 | if (leftCommand.category !== rightCommand.category) { |
| 504 | return leftCommand.category.localeCompare(rightCommand.category) |
| 505 | } |
| 506 | |
| 507 | return leftCommand.name.localeCompare(rightCommand.name) |
| 508 | }) |
| 509 | |
| 510 | export const readRecentCommands = async (historyPath = HISTORY_PATH): Promise<Record<string, number>> => { |
| 511 | try { |
no test coverage detected