Skip to content

Commit ab296cc

Browse files
MasonNightclaude
andcommitted
fix(web): refresh keybinding labels when terminology changes
Restore defaults can reset the terminology while the keybindings page stays mounted, leaving labels read from the non-reactive mirror stale. The catalog now subscribes once and stores each command's label on its row and option. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 26f87ed commit ab296cc

3 files changed

Lines changed: 53 additions & 19 deletions

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
} from "@t3tools/shared/keybindings";
77

88
import { resolveShortcutCommand } from "../../keybindings";
9-
import { setMergeRequestTerms } from "@t3tools/client-runtime/source-control-clients";
9+
import {
10+
changeRequestTerms,
11+
setMergeRequestTerms,
12+
} from "@t3tools/client-runtime/source-control-clients";
1013

1114
import {
1215
buildKeybindingRows,
@@ -29,6 +32,17 @@ describe("KeybindingsSettings.logic", () => {
2932
setMergeRequestTerms(false);
3033
}
3134
expect(commandLabel("pullRequest.copyNumber")).toBe("Pull Request: Copy Number");
35+
36+
const mergeRequestTerms = changeRequestTerms(true);
37+
expect(commandLabel("pullRequest.copyNumber", mergeRequestTerms)).toBe(
38+
"Merge Request: Copy Number",
39+
);
40+
const rows = buildKeybindingRows(
41+
compileResolvedKeybindingsConfig([{ command: "pullRequest.copyNumber", key: "mod+shift+c" }]),
42+
undefined,
43+
mergeRequestTerms,
44+
);
45+
expect(rows.map((row) => row.label)).toEqual(["Merge Request: Copy Number"]);
3246
});
3347

3448
it("keeps sibling row identities when a saved binding moves to the end", () => {

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { formatChangeRequestText } from "@t3tools/client-runtime/source-control-clients";
1+
import {
2+
currentChangeRequestTerms,
3+
formatChangeRequestText,
4+
} from "@t3tools/client-runtime/source-control-clients";
25
import {
36
STATIC_KEYBINDING_COMMANDS,
47
type KeybindingCommand,
@@ -46,6 +49,7 @@ export type KeybindingSource = "Default" | "Custom" | "Project";
4649
export interface KeybindingRow {
4750
readonly id: string;
4851
readonly command: KeybindingCommand;
52+
readonly label: string;
4953
readonly key: string;
5054
readonly when: string;
5155
readonly source: KeybindingSource;
@@ -56,7 +60,10 @@ export interface KeybindingRow {
5660
}
5761

5862
export type WhenVariableOption = string;
59-
export type KeybindingCommandOption = KeybindingCommand;
63+
export interface KeybindingCommandOption {
64+
readonly command: KeybindingCommand;
65+
readonly label: string;
66+
}
6067

6168
const CORE_WHEN_VARIABLES = [
6269
"terminalFocus",
@@ -196,7 +203,7 @@ export function keybindingConflictLabels(
196203
shortcutConflictKey(candidate.binding.shortcut, platform) === conflictKey &&
197204
conflictsWithWhen(candidate.when, input.when)
198205
) {
199-
conflicts.push(commandLabel(candidate.command));
206+
conflicts.push(candidate.label);
200207
}
201208
}
202209
return [...new Set(conflicts)].toSorted();
@@ -250,6 +257,7 @@ export function groupKeybindingRows(
250257
export function buildKeybindingRows(
251258
keybindings: ResolvedKeybindingsConfig,
252259
platform = navigator.platform,
260+
terms = currentChangeRequestTerms(),
253261
): ReadonlyArray<KeybindingRow> {
254262
const rowsById = new Map<string, KeybindingRow>();
255263
for (const binding of keybindings) {
@@ -260,6 +268,7 @@ export function buildKeybindingRows(
260268
rowsById.set(id, {
261269
id,
262270
command: binding.command,
271+
label: commandLabel(binding.command, terms),
263272
key,
264273
when,
265274
source: sourceForBinding(binding),
@@ -304,7 +313,7 @@ export function filterKeybindingRows(
304313
return rows.filter((row) => {
305314
return (
306315
row.command.toLowerCase().includes(normalizedQuery) ||
307-
commandLabel(row.command).toLowerCase().includes(normalizedQuery) ||
316+
row.label.toLowerCase().includes(normalizedQuery) ||
308317
row.key.toLowerCase().includes(normalizedQuery) ||
309318
row.when.toLowerCase().includes(normalizedQuery) ||
310319
row.source.toLowerCase().includes(normalizedQuery)
@@ -360,15 +369,23 @@ export function buildWhenVariableOptions(): ReadonlyArray<WhenVariableOption> {
360369

361370
export function buildKeybindingCommandOptions(
362371
keybindings: ResolvedKeybindingsConfig,
372+
terms = currentChangeRequestTerms(),
363373
): ReadonlyArray<KeybindingCommandOption> {
364374
const commands = new Set<KeybindingCommand>(STATIC_KEYBINDING_COMMANDS);
365375
for (const binding of keybindings) {
366376
commands.add(binding.command);
367377
}
368-
return [...commands].toSorted((left, right) => compareCommands(left, right, commandLabel));
378+
return [...commands]
379+
.toSorted((left, right) =>
380+
compareCommands(left, right, (command) => commandLabel(command, terms)),
381+
)
382+
.map((command) => ({ command, label: commandLabel(command, terms) }));
369383
}
370384

371-
export function commandLabel(command: KeybindingCommand): string {
385+
export function commandLabel(
386+
command: KeybindingCommand,
387+
terms = currentChangeRequestTerms(),
388+
): string {
372389
if (command === "workspace.focusNext") return "Focus Next Workspace Area";
373390
if (command === "workspace.focusPrevious") return "Focus Previous Workspace Area";
374391
if (command === "composer.sendAlternate") return "Composer: Opposite Queue or Steer Action";
@@ -377,7 +394,7 @@ export function commandLabel(command: KeybindingCommand): string {
377394
if (command === "thread.steerQueuedMessage") return "Queue: Send First Queued Message";
378395
if (command === "thread.editQueuedMessage") return "Queue: Edit Last Queued Message";
379396
if (command === "thread.copyReference")
380-
return formatChangeRequestText("Pull Request: Copy Link or Thread");
397+
return formatChangeRequestText("Pull Request: Copy Link or Thread", terms);
381398
const usageMetric = METRIC_OPTIONS.find((option) => option.command === command);
382399
if (usageMetric) return `Usage: ${usageMetric.label}`;
383400
const usagePeriod = WINDOW_OPTIONS.find((option) => option.command === command);
@@ -388,7 +405,7 @@ export function commandLabel(command: KeybindingCommand): string {
388405
if (raw.startsWith("script.") && raw.endsWith(".run")) {
389406
return `Run Script: ${titleCaseCommandSegment(raw.slice("script.".length, -".run".length))}`;
390407
}
391-
return formatChangeRequestText(raw.split(".").map(titleCaseCommandSegment).join(": "));
408+
return formatChangeRequestText(raw.split(".").map(titleCaseCommandSegment).join(": "), terms);
392409
}
393410

394411
function titleCaseCommandSegment(segment: string): string {

‎apps/web/src/components/settings/KeybindingsSettings.tsx‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { isElectron } from "../../env";
3939
import { useOpenInPreferredEditor } from "../../editorPreferences";
4040
import { formatShortcutLabel } from "../../keybindings";
4141
import { cn } from "../../lib/utils";
42+
import { useChangeRequestTerms } from "../../hooks/useSettings";
4243
import { serverEnvironment } from "../../state/server";
4344
import { useSettingsScope } from "./SettingsScopeContext";
4445
import { Badge } from "../ui/badge";
@@ -827,7 +828,7 @@ function KeybindingKeyControl({
827828
ref={pillRef}
828829
type="button"
829830
onClick={() => setDraft({ isRecording: true })}
830-
aria-label={`Edit shortcut for ${commandLabel(row.command)}: ${formatShortcutLabel(row.binding.shortcut)}`}
831+
aria-label={`Edit shortcut for ${row.label}: ${formatShortcutLabel(row.binding.shortcut)}`}
831832
className={cn(
832833
"inline-flex h-8 cursor-pointer items-center rounded-md border border-transparent px-1.5 sm:h-7 outline-none transition-colors hover:border-border/70 hover:bg-accent focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-inset focus-visible:ring-ring/24",
833834
pillClassName,
@@ -839,7 +840,7 @@ function KeybindingKeyControl({
839840
<Input
840841
data-keybinding-capture=""
841842
autoFocus={isRecording}
842-
aria-label={`Keybinding for ${commandLabel(row.command)}`}
843+
aria-label={`Keybinding for ${row.label}`}
843844
value={isRecording ? "" : keyDraft}
844845
placeholder={isRecording ? "Press shortcut" : "Unassigned"}
845846
size="sm"
@@ -926,7 +927,7 @@ function KeybindingRowMenu({
926927
variant="ghost-muted"
927928
size="icon-sm"
928929
disabled={isSaving}
929-
aria-label={`Actions for ${commandLabel(row.command)}`}
930+
aria-label={`Actions for ${row.label}`}
930931
/>
931932
}
932933
>
@@ -961,7 +962,7 @@ function KeybindingRowTitle({ row }: { row: KeybindingRow }) {
961962
return (
962963
<Tooltip>
963964
<TooltipTrigger render={<span className="flex items-center gap-2" />}>
964-
{commandLabel(row.command)}
965+
{row.label}
965966
<KeybindingSourceBadge source={row.source} />
966967
</TooltipTrigger>
967968
<TooltipPopup side="top">{row.command}</TooltipPopup>
@@ -982,7 +983,7 @@ function KeybindingRowWhen({
982983
<span className="flex h-6 items-center gap-1.5">
983984
<span className="text-xs leading-none text-muted-foreground/70">When</span>
984985
<WhenClauseControl
985-
label={commandLabel(row.command)}
986+
label={row.label}
986987
expression={editor.whenDraftExpression}
987988
value={editor.whenDraft}
988989
variables={variables}
@@ -1058,7 +1059,8 @@ function useNewKeybindingDraft({
10581059
key: keyDraft,
10591060
when: whenDraftExpression,
10601061
});
1061-
const commandLabelText = commandDraft ? commandLabel(commandDraft) : "new keybinding";
1062+
const terms = useChangeRequestTerms();
1063+
const commandLabelText = commandDraft ? commandLabel(commandDraft, terms) : "new keybinding";
10621064
const canSave = Boolean(commandDraft) && keyDraft.trim().length > 0 && isWhenDraftValid;
10631065

10641066
const save = () => {
@@ -1132,9 +1134,9 @@ function NewKeybindingCommandSelect({
11321134
<SelectValue placeholder="Command" />
11331135
</SelectTrigger>
11341136
<SelectContent alignItemWithTrigger={false} matchTriggerWidth={false} className="max-h-72">
1135-
{commandOptions.map((command) => (
1137+
{commandOptions.map(({ command, label }) => (
11361138
<SelectItem key={command} value={command} className="w-full">
1137-
<span className="truncate">{commandLabel(command)}</span>
1139+
<span className="truncate">{label}</span>
11381140
</SelectItem>
11391141
))}
11401142
</SelectContent>
@@ -1305,10 +1307,11 @@ function keybindingAnchorIds(rows: ReturnType<typeof buildKeybindingRows>) {
13051307
// Cache rows in a separate hook so the compiler does not rebuild them per search keystroke.
13061308
function useKeybindingCatalog() {
13071309
const serverKeybindings = useSettingsScope().environment?.serverConfig?.keybindings;
1310+
const terms = useChangeRequestTerms();
13081311
const merged = mergeWithDefaultKeybindings(serverKeybindings ?? []);
13091312
return {
1310-
commandOptions: buildKeybindingCommandOptions(merged),
1311-
allRows: buildKeybindingRows(merged),
1313+
commandOptions: buildKeybindingCommandOptions(merged, terms),
1314+
allRows: buildKeybindingRows(merged, undefined, terms),
13121315
};
13131316
}
13141317

0 commit comments

Comments
 (0)