Skip to content

Commit 8aec848

Browse files
committed
fix(web): honor the send shortcut for follow-up actions
1 parent 89b42bf commit 8aec848

7 files changed

Lines changed: 191 additions & 58 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ import { useActiveThreadRef } from "../hooks/useActiveThreadRef";
170170
import {
171171
type ComposerSubmissionIntent,
172172
collapseExpandedComposerCursor,
173+
composerRequiresModifier,
173174
parseStandaloneComposerSlashCommand,
174175
} from "../composer-logic";
175176
import {
@@ -5553,6 +5554,7 @@ export default function ChatView(props: ChatViewProps) {
55535554
composerFocus: document.activeElement?.getAttribute("data-testid") === "composer-editor",
55545555
draftThreadRoute: routeKind === "draft",
55555556
turnRunning: phase === "running",
5557+
composerRequiresModifier: composerRequiresModifier(settings.sendShortcut, promptRef.current),
55565558
isWeb: !isElectron,
55575559
isDesktop: isElectron,
55585560
});

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import {
8383
type ComposerTrigger,
8484
type ComposerSubmissionIntent,
8585
collapseExpandedComposerCursor,
86+
composerRequiresModifier,
8687
composerSubmissionIntentForKey,
8788
composerStateAtPromptEnd,
8889
detectComposerTrigger,
@@ -7301,6 +7302,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
73017302
composerFocus: true,
73027303
draftThreadRoute: routeKind === "draft",
73037304
turnRunning: true,
7305+
composerRequiresModifier: composerRequiresModifier(
7306+
settings.sendShortcut,
7307+
prompt,
7308+
),
73047309
},
73057310
},
73067311
)}

‎apps/web/src/composer-logic.test.ts‎

Lines changed: 108 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,41 @@ describe("composerSubmissionIntentForKey", () => {
102102
metaKey: platform === "MacIntel",
103103
ctrlKey: platform !== "MacIntel",
104104
};
105-
for (const sendShortcut of ["enter", "mod-enter", "mod-enter-multiline"] as const) {
106-
const running = { ...input, platform, sendShortcut, prompt: "two\nlines", isRunning: true };
105+
for (const [sendShortcut, prompt, requiresModifier] of [
106+
["enter", "one line", false],
107+
["enter", "two\nlines", false],
108+
["mod-enter", "one line", true],
109+
["mod-enter", "two\nlines", true],
110+
["mod-enter-multiline", "one line", false],
111+
["mod-enter-multiline", "two\nlines", true],
112+
] as const) {
113+
const running = { ...input, platform, sendShortcut, prompt, isRunning: true };
107114
const intent = composerSubmissionIntentForKey({ ...running, event: modEnter });
108-
expect(intent).toBe("alternate");
115+
expect(intent).toBe(requiresModifier ? "foreground" : "alternate");
116+
const alternateIntent = composerSubmissionIntentForKey({
117+
...running,
118+
event: { ...modEnter, shiftKey: requiresModifier },
119+
});
120+
expect(alternateIntent).toBe("alternate");
121+
expect(composerSubmissionIntentForKey({ ...running, event: enter })).toBe(
122+
requiresModifier ? null : "foreground",
123+
);
109124
for (const activeTurnDefault of ["queue", "steer"] as const) {
110125
expect(
111126
resolveComposerDispatchMode({
112127
running: true,
113128
alternateModifier: intent === "alternate",
114129
activeTurnDefault,
115130
}),
131+
).toBe(
132+
requiresModifier ? activeTurnDefault : activeTurnDefault === "queue" ? "steer" : "queue",
133+
);
134+
expect(
135+
resolveComposerDispatchMode({
136+
running: true,
137+
alternateModifier: alternateIntent === "alternate",
138+
activeTurnDefault,
139+
}),
116140
).toBe(activeTurnDefault === "queue" ? "steer" : "queue");
117141
}
118142
expect(
@@ -137,6 +161,7 @@ describe("composerSubmissionIntentForKey", () => {
137161
...input,
138162
platform,
139163
sendShortcut,
164+
prompt,
140165
isDraftThread: true,
141166
event: modEnter,
142167
}),
@@ -157,6 +182,28 @@ describe("composerSubmissionIntentForKey", () => {
157182
).toBeNull();
158183
});
159184

185+
it("honors the send preference with an existing install's saved alternate binding", () => {
186+
const keybindings = mergeWithDefaultKeybindings(
187+
compileResolvedKeybindingsConfig([
188+
{
189+
key: "mod+enter",
190+
command: "composer.sendAlternate",
191+
when: "composerFocus && turnRunning",
192+
},
193+
]),
194+
);
195+
const running = { ...input, keybindings, isRunning: true, sendShortcut: "mod-enter" as const };
196+
expect(composerSubmissionIntentForKey({ ...running, event: { ...enter, ctrlKey: true } })).toBe(
197+
"foreground",
198+
);
199+
expect(
200+
composerSubmissionIntentForKey({
201+
...running,
202+
event: { ...enter, ctrlKey: true, shiftKey: true },
203+
}),
204+
).toBe("alternate");
205+
});
206+
160207
it("does not start a background thread with the queued-message shortcut", () => {
161208
expect(
162209
composerSubmissionIntentForKey({
@@ -186,54 +233,64 @@ describe("composerSubmissionIntentForKey", () => {
186233
).toBe("background");
187234
});
188235

189-
it("uses remapped keys and removes the old action bindings", () => {
190-
const keybindings = mergeWithDefaultKeybindings(
191-
compileResolvedKeybindingsConfig([
192-
{
193-
key: "alt+q",
194-
command: "composer.sendAlternate",
195-
when: "composerFocus && turnRunning",
196-
},
197-
{
198-
key: "alt+b",
199-
command: "composer.sendBackground",
200-
when: "composerFocus && draftThreadRoute",
201-
},
202-
]),
203-
);
204-
const custom = { ...input, keybindings };
205-
expect(
206-
composerSubmissionIntentForKey({
207-
...custom,
208-
isRunning: true,
209-
event: { ...enter, key: "q", altKey: true },
210-
}),
211-
).toBe("alternate");
212-
expect(
213-
composerSubmissionIntentForKey({
214-
...custom,
215-
isDraftThread: true,
216-
event: { ...enter, key: "b", altKey: true },
217-
}),
218-
).toBe("background");
219-
expect(
220-
composerSubmissionIntentForKey({
221-
...custom,
222-
isRunning: true,
223-
event: { ...enter, ctrlKey: true },
224-
}),
225-
).toBe("foreground");
226-
expect(
227-
composerSubmissionIntentForKey({
228-
...custom,
229-
isDraftThread: true,
230-
event: { ...enter, ctrlKey: true, shiftKey: true },
231-
}),
232-
).toBeNull();
233-
expect(
234-
composerSubmissionIntentForKey({ ...custom, event: { ...enter, key: "b", altKey: true } }),
235-
).toBeNull();
236-
});
236+
it.each(["enter", "mod-enter", "mod-enter-multiline"] as const)(
237+
"uses remapped keys and removes the old action bindings with %s",
238+
(sendShortcut) => {
239+
const keybindings = mergeWithDefaultKeybindings(
240+
compileResolvedKeybindingsConfig([
241+
{
242+
key: "alt+q",
243+
command: "composer.sendAlternate",
244+
when: "composerFocus && turnRunning",
245+
},
246+
{
247+
key: "alt+b",
248+
command: "composer.sendBackground",
249+
when: "composerFocus && draftThreadRoute",
250+
},
251+
]),
252+
);
253+
const custom = { ...input, keybindings, sendShortcut, prompt: "two\nlines" };
254+
expect(
255+
composerSubmissionIntentForKey({
256+
...custom,
257+
isRunning: true,
258+
event: { ...enter, key: "q", altKey: true },
259+
}),
260+
).toBe("alternate");
261+
expect(
262+
composerSubmissionIntentForKey({
263+
...custom,
264+
isDraftThread: true,
265+
event: { ...enter, key: "b", altKey: true },
266+
}),
267+
).toBe("background");
268+
expect(
269+
composerSubmissionIntentForKey({
270+
...custom,
271+
isRunning: true,
272+
event: { ...enter, ctrlKey: true },
273+
}),
274+
).toBe("foreground");
275+
expect(
276+
composerSubmissionIntentForKey({
277+
...custom,
278+
isDraftThread: true,
279+
event: { ...enter, ctrlKey: true, shiftKey: true },
280+
}),
281+
).toBeNull();
282+
expect(
283+
composerSubmissionIntentForKey({
284+
...custom,
285+
isRunning: true,
286+
event: { ...enter, ctrlKey: true, shiftKey: true },
287+
}),
288+
).toBeNull();
289+
expect(
290+
composerSubmissionIntentForKey({ ...custom, event: { ...enter, key: "b", altKey: true } }),
291+
).toBeNull();
292+
},
293+
);
237294

238295
it.each([
239296
{ isMobileViewport: true },

‎apps/web/src/composer-logic.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function formatAssistantCitationForComposer(citation: AssistantCitation,
2626
return `${serializeAssistantCitation(withAssistantCitationComment(citation, comment))} `;
2727
}
2828

29-
function composerRequiresModifier(
29+
export function composerRequiresModifier(
3030
sendShortcut: ClientSettings["sendShortcut"] | undefined,
3131
prompt: string,
3232
) {
@@ -55,6 +55,7 @@ export function composerSubmissionIntentForKey(input: {
5555
composerFocus: true,
5656
draftThreadRoute: input.isDraftThread,
5757
turnRunning: input.isRunning === true,
58+
composerRequiresModifier: composerRequiresModifier(input.sendShortcut, input.prompt ?? ""),
5859
},
5960
});
6061
if (command === "composer.sendAlternate" && input.isRunning) return "alternate";

‎apps/web/src/keybindings.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,48 @@ describe("composer and pull request shortcuts", () => {
14531453
["Enter", "thread.steerQueuedMessage"],
14541454
] as const;
14551455

1456+
it.each(["MacIntel", "Win32", "Linux"])(
1457+
"reserves the alternate send chord for the focused composer on %s",
1458+
(platform) => {
1459+
const modifier = {
1460+
metaKey: platform === "MacIntel",
1461+
ctrlKey: platform !== "MacIntel",
1462+
};
1463+
const shiftedEnter = event({ key: "Enter", shiftKey: true, ...modifier });
1464+
for (const composerRequiresModifier of [false, true]) {
1465+
const context = {
1466+
composerFocus: true,
1467+
turnRunning: true,
1468+
composerRequiresModifier,
1469+
};
1470+
assert.strictEqual(
1471+
resolveShortcutCommand(shiftedEnter, DEFAULT_RESOLVED_KEYBINDINGS, {
1472+
platform,
1473+
context,
1474+
}),
1475+
composerRequiresModifier ? "composer.sendAlternate" : "thread.steerQueuedMessage",
1476+
);
1477+
assert.strictEqual(
1478+
shortcutLabelForCommand(DEFAULT_RESOLVED_KEYBINDINGS, "composer.sendAlternate", {
1479+
platform,
1480+
context,
1481+
}),
1482+
formatShortcutLabel(
1483+
modShortcut("enter", { shiftKey: composerRequiresModifier }),
1484+
platform,
1485+
),
1486+
);
1487+
assert.strictEqual(
1488+
resolveShortcutCommand(shiftedEnter, DEFAULT_RESOLVED_KEYBINDINGS, {
1489+
platform,
1490+
context: { ...context, composerFocus: false },
1491+
}),
1492+
"thread.steerQueuedMessage",
1493+
);
1494+
}
1495+
},
1496+
);
1497+
14561498
it.each(["MacIntel", "Win32", "Linux"])(
14571499
"separates queued steering and background start on %s",
14581500
(platform) => {

‎apps/web/src/keybindings.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type KeybindingCommand,
33
type KeybindingShortcut,
44
type KeybindingWhenNode,
5+
type ResolvedKeybindingRule,
56
MODEL_PICKER_JUMP_KEYBINDING_COMMANDS,
67
type ResolvedKeybindingsConfig,
78
THREAD_JUMP_KEYBINDING_COMMANDS,
@@ -104,6 +105,25 @@ export function shortcutConflictKey(
104105
].join("|");
105106
}
106107

108+
function shortcutForContext(binding: ResolvedKeybindingRule, context: ShortcutMatchContext) {
109+
const shortcut = binding.shortcut;
110+
// Existing installs persist Mod+Enter. Resolve its alternate chord against
111+
// the send preference without rewriting saved or remapped shortcuts.
112+
if (
113+
context.composerRequiresModifier &&
114+
binding.command === "composer.sendAlternate" &&
115+
shortcut.key === "enter" &&
116+
shortcut.modKey &&
117+
!shortcut.metaKey &&
118+
!shortcut.ctrlKey &&
119+
!shortcut.altKey &&
120+
!shortcut.shiftKey
121+
) {
122+
return { ...shortcut, shiftKey: true };
123+
}
124+
return shortcut;
125+
}
126+
107127
export function effectiveShortcutsForCommand(
108128
keybindings: ResolvedKeybindingsConfig,
109129
command: KeybindingCommand,
@@ -119,14 +139,15 @@ export function effectiveShortcutsForCommand(
119139
if (!binding) continue;
120140
if (!matchesWhenClause(binding.whenAst, context)) continue;
121141

122-
const conflictKey = shortcutConflictKey(binding.shortcut, platform);
142+
const shortcut = shortcutForContext(binding, context);
143+
const conflictKey = shortcutConflictKey(shortcut, platform);
123144
if (claimedShortcuts.has(conflictKey)) {
124145
continue;
125146
}
126147

127148
claimedShortcuts.add(conflictKey);
128149
if (binding.command === command) {
129-
effective.push(binding.shortcut);
150+
effective.push(shortcut);
130151
}
131152
}
132153

@@ -162,7 +183,7 @@ export function resolveShortcutCommand(
162183
const binding = keybindings[index];
163184
if (!binding) continue;
164185
if (!matchesWhenClause(binding.whenAst, context)) continue;
165-
if (!matchesKeybindingShortcut(event, binding.shortcut, platform)) continue;
186+
if (!matchesKeybindingShortcut(event, shortcutForContext(binding, context), platform)) continue;
166187
return binding.command;
167188
}
168189
return null;

‎docs/user/composer.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ On web and desktop, choose **Settings → General → Follow-up behavior** to qu
5555
new messages for a later turn or steer the running turn immediately. The setting
5656
applies to this client; already queued messages keep their place. Queued messages
5757
are saved on the server and can be edited, reordered, or removed above the composer.
58-
`Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux uses the opposite action:
59-
it steers when your default is Queue and queues when your default is Steer.
58+
When Enter sends, `Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux uses
59+
the opposite action: it steers when your default is Queue and queues when your
60+
default is Steer.
61+
If your **Send shortcut** requires `Cmd+Enter` or `Ctrl+Enter`, that shortcut uses
62+
your default follow-up behavior; add **Shift** to use the opposite action. This
63+
applies only to multiline messages when you choose the multiline send option.
6064

6165
Use `Cmd+Shift+Enter` on macOS or `Ctrl+Shift+Enter` on Windows and Linux to send
6266
the oldest queued message as a steer. This leaves the current draft intact and
63-
requires an active turn that supports steering. Change
67+
requires an active turn that supports steering. If that shortcut sends the opposite
68+
action for your draft, move focus outside the composer to steer the queued message. Change
6469
`thread.steerQueuedMessage` in **Settings → Keybindings** to use another shortcut.
6570

6671
Press `Option+Up` on macOS or `Alt+Up` on Windows and Linux with the cursor at the

0 commit comments

Comments
 (0)