Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6091,6 +6091,13 @@ export default function ChatView(props: ChatViewProps) {
});
if (!command) return;

if (command === "composer.focus") {
event.preventDefault();
event.stopPropagation();
focusComposer();
return;
}

if (command === "thread.copyReference") {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -6292,6 +6299,7 @@ export default function ChatView(props: ChatViewProps) {
supportsSettlement,
confirmAndUnpinThread,
copyActiveThreadReference,
focusComposer,
previewPanelOpen,
toggleRightPanel,
toggleRightPanelMaximized,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ describe("KeybindingsSettings.logic", () => {
expect(options).toEqual(
expect.arrayContaining([
"chat.new",
"composer.focus",
"rightPanel.toggleMaximized",
"thread.stop",
"script.setup-db.run",
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,29 @@ describe("cross-command precedence", () => {
});

describe("resolveShortcutCommand", () => {
it.each(["MacIntel", "Win32", "Linux"])(
"resolves a custom composer-focus shortcut inside and outside terminals on %s",
(platform) => {
const keybindings = compile([
{ shortcut: modShortcut("i", { shiftKey: true }), command: "composer.focus" },
]);
const input = event({
key: "i",
shiftKey: true,
metaKey: platform === "MacIntel",
ctrlKey: platform !== "MacIntel",
});

for (const terminalFocus of [false, true]) {
assert.strictEqual(
resolveShortcutCommand(input, keybindings, { platform, context: { terminalFocus } }),
"composer.focus",
);
assert.isNull(resolveShortcutCommand(input, [], { platform }));
}
},
);

it("resolves a custom stop-thread shortcut", () => {
const keybindings = compile([{ shortcut: modShortcut("escape"), command: "thread.stop" }]);

Expand Down
4 changes: 4 additions & 0 deletions docs/user/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ a shortcut.

## Commands with special behavior

`composer.focus` moves focus to the end of the current thread's composer, including
from a terminal. It has no default shortcut; assign one with **Add keybinding** in
**Settings → Keybindings**.

`thread.stop` interrupts the running turn in the focused thread. It has no default
shortcut; assign one in **Settings → Keybindings**.

Expand Down
6 changes: 6 additions & 0 deletions packages/contracts/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ it.effect("parses keybinding rules", () =>
});
assert.strictEqual(parsedThemeEditor.command, "themeEditor.toggle");

const parsedComposerFocus = yield* decode(KeybindingRule, {
key: "mod+shift+i",
command: "composer.focus",
});
assert.strictEqual(parsedComposerFocus.command, "composer.focus");

const parsedLocal = yield* decode(KeybindingRule, {
key: "mod+shift+n",
command: "chat.newLocal",
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const STATIC_KEYBINDING_COMMANDS = [
"filePicker.toggle",
"projectSearch.toggle",
"themeEditor.toggle",
"composer.focus",
"composer.stash",
"chat.new",
"chat.newLocal",
Expand Down
Loading