Skip to content

Commit 37ea301

Browse files
committed
fix(web): send mod-enter drafts in the foreground
Cmd+Enter was the send key and the background-start key on a new thread, so the first message always started in the background.
1 parent c2fa9fc commit 37ea301

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ describe("composerSubmissionIntentForEnter", () => {
152152
).toBe("background");
153153
});
154154

155+
it.each([
156+
["mod-enter", "one line", false, "foreground"],
157+
["mod-enter", "two\nlines", false, "foreground"],
158+
["mod-enter-multiline", "two\nlines", false, "foreground"],
159+
["mod-enter-multiline", "one line", false, "background"],
160+
["enter", "one line", false, "background"],
161+
["mod-enter", "one line", true, "background"],
162+
["mod-enter-multiline", "two\nlines", true, "background"],
163+
["enter", "one line", true, null],
164+
] as const)(
165+
"resolves a draft with %s for %j and shift=%s",
166+
(sendShortcut, prompt, shiftKey, expected) => {
167+
expect(
168+
composerSubmissionIntentForEnter({
169+
isMobileViewport: false,
170+
shiftKey,
171+
modifierKey: true,
172+
isDraftThread: true,
173+
sendShortcut,
174+
prompt,
175+
}),
176+
).toBe(expected);
177+
},
178+
);
179+
155180
it("keeps Mod+Enter in the foreground for an active thread", () => {
156181
expect(
157182
composerSubmissionIntentForEnter({

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ export function composerSubmissionIntentForEnter(input: {
3737
input.sendShortcut === "mod-enter" ||
3838
(input.sendShortcut === "mod-enter-multiline" && /[\r\n]/.test(input.prompt ?? ""));
3939
if (input.isMobileViewport || (requiresModifier && !input.modifierKey)) return null;
40-
if (input.shiftKey && !(requiresModifier && input.modifierKey && input.isRunning)) return null;
40+
if (
41+
input.shiftKey &&
42+
!(requiresModifier && input.modifierKey && (input.isRunning || input.isDraftThread))
43+
) {
44+
return null;
45+
}
4146
if (input.isRunning && input.modifierKey && (!requiresModifier || input.shiftKey)) {
4247
return "alternate";
4348
}
44-
return input.modifierKey && input.isDraftThread ? "background" : "foreground";
49+
if (input.modifierKey && input.isDraftThread && (!requiresModifier || input.shiftKey)) {
50+
return "background";
51+
}
52+
return "foreground";
4553
}
4654

4755
const isInlineTokenSegment = (segment: ComposerPromptSegment): boolean => segment.type !== "text";

‎docs/user/keybindings.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ inserts a new line. This applies to the web and desktop composer at desktop widt
1111

1212
**Follow-up behavior** chooses Queue or Steer while the agent runs. Use
1313
`mod+Enter` to do the opposite for one message. When sending requires `mod+Enter`,
14-
use `mod+Shift+Enter` for the opposite action. In a new thread, `mod+Enter` keeps
15-
starting the thread in the background.
14+
use `mod+Shift+Enter` for the opposite action. In a new thread, `mod+Enter`
15+
starts the thread in the background when Enter itself sends. When sending
16+
requires `mod+Enter`, `mod+Shift+Enter` starts that thread in the background.
1617

1718
Use `mod+shift+m` to choose a model and `mod+shift+h` to choose a host.
1819
Use `mod+shift+e` for effort, `mod+shift+a` for access mode, `mod+shift+x` for the

0 commit comments

Comments
 (0)