GeezerVison is showing github.com — fix(web): port #10158 to V2 — Usage shortcuts sort the same whatever … · pingdotgg/t3code@1b10d08
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/settings
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/KeybindingsSettings.logic.test.ts +11-6Lines changed: 11 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,20 +60,25 @@ describe("KeybindingsSettings.logic", () => { | 60 | 60 | ); | 61 | 61 | it("orders Usage bindings and command choices like the page", () => { | 62 | 62 | const expected = [ | 63 | | - "usage.cost", | 64 | 63 | "usage.open", | | 64 | + "usage.cost", | 65 | 65 | "usage.tokens", | 66 | 66 | "usage.limits", | 67 | 67 | "usage.period.day", | 68 | 68 | "usage.period.week", | 69 | 69 | "usage.period.month", | 70 | 70 | "usage.period.quarter", | 71 | 71 | ]; | 72 | | - const bindings = DEFAULT_RESOLVED_KEYBINDINGS.toReversed(); | 73 | | - expect(buildKeybindingRows(bindings, "usage").map((row) => row.command)).toEqual(expected); | 74 | | - expect( | 75 | | - buildKeybindingCommandOptions(bindings).filter((command) => command.startsWith("usage.")), | 76 | | - ).toEqual(expected); | | 72 | + // The order must not depend on the order of the configured bindings. | | 73 | + for (const bindings of [ | | 74 | + DEFAULT_RESOLVED_KEYBINDINGS, | | 75 | + DEFAULT_RESOLVED_KEYBINDINGS.toReversed(), | | 76 | + ]) { | | 77 | + expect(buildKeybindingRows(bindings, "usage").map((row) => row.command)).toEqual(expected); | | 78 | + expect( | | 79 | + buildKeybindingCommandOptions(bindings).filter((command) => command.startsWith("usage.")), | | 80 | + ).toEqual(expected); | | 81 | + } | 77 | 82 | }); | 78 | 83 |
| 79 | 84 | it("builds searchable rows with readable key and when values", () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/KeybindingsSettings.logic.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,8 +15,14 @@ import { shortcutKeyFromEvent } from "../../keybindings"; | 15 | 15 | import { isMacPlatform } from "../../lib/utils"; | 16 | 16 | import { METRIC_OPTIONS, WINDOW_OPTIONS } from "../usage/usageShortcuts"; | 17 | 17 |
| | 18 | +// Every usage.* command needs a rank. An unranked one falls back to the | | 19 | +// alphabetical compare, which makes the comparator inconsistent and the order | | 20 | +// depend on the input order. | 18 | 21 | const usageCommandOrder = new Map<KeybindingCommand, number>( | 19 | | - [...METRIC_OPTIONS, ...WINDOW_OPTIONS].map((option, index) => [option.command, index]), | | 22 | + [ | | 23 | + "usage.open" as const, | | 24 | + ...[...METRIC_OPTIONS, ...WINDOW_OPTIONS].map((option) => option.command), | | 25 | + ].map((command, index) => [command, index]), | 20 | 26 | ); | 21 | 27 |
| 22 | 28 | function compareUsageCommands(left: KeybindingCommand, right: KeybindingCommand): number | null { | |
|