Skip to content

Commit 1b10d08

Browse files
fix(web): port #10158 to V2 — Usage shortcuts sort the same whatever the binding order
Main's keybindings settings rank the Usage page commands by the page's own order but left usage.open unranked. An unranked command fell back to an alphabetical compare, so the comparator was inconsistent and the list order depended on the input order. With V2's extra default bindings (threadPanel.toggle, composer.sendAlternate, ...) the settings list put Open between Tokens and Limits, and main's own test failed on this branch. usage.open now ranks first, and the test checks both input orders. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 8119814 commit 1b10d08

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎apps/web/src/components/settings/KeybindingsSettings.logic.test.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,25 @@ describe("KeybindingsSettings.logic", () => {
6060
);
6161
it("orders Usage bindings and command choices like the page", () => {
6262
const expected = [
63-
"usage.cost",
6463
"usage.open",
64+
"usage.cost",
6565
"usage.tokens",
6666
"usage.limits",
6767
"usage.period.day",
6868
"usage.period.week",
6969
"usage.period.month",
7070
"usage.period.quarter",
7171
];
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+
}
7782
});
7883

7984
it("builds searchable rows with readable key and when values", () => {

‎apps/web/src/components/settings/KeybindingsSettings.logic.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ import { shortcutKeyFromEvent } from "../../keybindings";
1515
import { isMacPlatform } from "../../lib/utils";
1616
import { METRIC_OPTIONS, WINDOW_OPTIONS } from "../usage/usageShortcuts";
1717

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.
1821
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]),
2026
);
2127

2228
function compareUsageCommands(left: KeybindingCommand, right: KeybindingCommand): number | null {

0 commit comments

Comments
 (0)