Skip to content

Commit 8cb3344

Browse files
committed
feat(web): add configurable settle shortcut
1 parent cbd55d6 commit 8cb3344

7 files changed

Lines changed: 74 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe("KeybindingsSettings.logic", () => {
135135
expect(options).not.toContain("customModeActive");
136136
});
137137

138-
it("builds command options from defaults and resolved project bindings", () => {
138+
it("builds command options from supported commands and resolved project bindings", () => {
139139
const options = buildKeybindingCommandOptions([
140140
{
141141
command: "script.setup-db.run",
@@ -150,7 +150,9 @@ describe("KeybindingsSettings.logic", () => {
150150
},
151151
] satisfies ResolvedKeybindingsConfig);
152152

153-
expect(options).toEqual(expect.arrayContaining(["chat.new", "script.setup-db.run"]));
153+
expect(options).toEqual(
154+
expect.arrayContaining(["chat.new", "thread.settle", "script.setup-db.run"]),
155+
);
154156
});
155157

156158
it("reports unknown when variables without rejecting parseable expressions", () => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
STATIC_KEYBINDING_COMMANDS,
23
type KeybindingCommand,
34
type KeybindingShortcut,
45
type KeybindingWhenNode,
@@ -255,7 +256,7 @@ export function buildWhenVariableOptions(): ReadonlyArray<WhenVariableOption> {
255256
export function buildKeybindingCommandOptions(
256257
keybindings: ResolvedKeybindingsConfig,
257258
): ReadonlyArray<KeybindingCommandOption> {
258-
const commands = new Set<KeybindingCommand>();
259+
const commands = new Set<KeybindingCommand>(STATIC_KEYBINDING_COMMANDS);
259260
for (const binding of DEFAULT_RESOLVED_KEYBINDINGS) {
260261
commands.add(binding.command);
261262
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,31 @@ describe("model picker navigation helpers", () => {
480480
});
481481

482482
describe("chat/editor shortcuts", () => {
483+
it("matches a configured thread settle shortcut", () => {
484+
const bindings = compile([
485+
{
486+
shortcut: modShortcut("s", { shiftKey: true }),
487+
command: "thread.settle",
488+
whenAst: whenNot(whenIdentifier("terminalFocus")),
489+
},
490+
]);
491+
492+
assert.strictEqual(
493+
resolveShortcutCommand(event({ key: "s", metaKey: true, shiftKey: true }), bindings, {
494+
platform: "MacIntel",
495+
context: { terminalFocus: false },
496+
}),
497+
"thread.settle",
498+
);
499+
assert.strictEqual(
500+
resolveShortcutCommand(event({ key: "s", metaKey: true, shiftKey: true }), bindings, {
501+
platform: "MacIntel",
502+
context: { terminalFocus: true },
503+
}),
504+
null,
505+
);
506+
});
507+
483508
it("matches chat.new shortcut", () => {
484509
assert.isTrue(
485510
isChatNewShortcut(event({ key: "o", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {

‎apps/web/src/routes/_chat.tsx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
22
import { useAtomValue } from "@effect/atom-react";
3+
import {
4+
isAtomCommandInterrupted,
5+
squashAtomCommandFailure,
6+
} from "@t3tools/client-runtime/state/runtime";
37
import { useEffect, useMemo } from "react";
48

59
import { isCommandPaletteOpen } from "../commandPaletteBus";
@@ -11,6 +15,7 @@ import { selectProjectGroupingSettings } from "../logicalProject";
1115
import { buildSidebarProjectSnapshots } from "../sidebarProjectGrouping";
1216
import { dispatchPreviewAction } from "../components/preview/previewActionBus";
1317
import { useHandleNewThread } from "../hooks/useHandleNewThread";
18+
import { useThreadActions } from "../hooks/useThreadActions";
1419
import { startNewThreadFromContext } from "../lib/chatThreadActions";
1520
import { isPreviewFocused } from "../lib/previewFocus";
1621
import { isTerminalFocused } from "../lib/terminalFocus";
@@ -27,6 +32,7 @@ function ChatRouteGlobalShortcuts() {
2732
const selectedThreadKeysSize = useThreadSelectionStore((state) => state.selectedThreadKeys.size);
2833
const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread, routeThreadRef } =
2934
useHandleNewThread();
35+
const { settleThread } = useThreadActions();
3036
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
3137
const legacySidebarEnabled = useLegacySidebarEnabled();
3238
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
@@ -108,6 +114,26 @@ function ChatRouteGlobalShortcuts() {
108114
return;
109115
}
110116

117+
if (command === "thread.settle") {
118+
event.preventDefault();
119+
event.stopPropagation();
120+
if (!routeThreadRef || event.repeat) return;
121+
void (async () => {
122+
const result = await settleThread(routeThreadRef);
123+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
124+
const error = squashAtomCommandFailure(result);
125+
toastManager.add(
126+
stackedThreadToast({
127+
type: "error",
128+
title: "Failed to settle thread",
129+
description: error instanceof Error ? error.message : "An error occurred.",
130+
}),
131+
);
132+
}
133+
})();
134+
return;
135+
}
136+
111137
if (command === "preview.toggle") {
112138
event.preventDefault();
113139
event.stopPropagation();
@@ -167,6 +193,7 @@ function ChatRouteGlobalShortcuts() {
167193
projectGroupCount,
168194
routeThreadRef,
169195
selectedThreadKeysSize,
196+
settleThread,
170197
legacySidebarEnabled,
171198
terminalOpen,
172199
]);

‎docs/user/keybindings.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Examples: `mod+j`, `mod+shift+d`, `ctrl+l`, `cmd+k`.
3737
Commands are IDs like `terminal.toggle`, `commandPalette.toggle`, `preview.refresh`, and
3838
`chat.new`. Project scripts are addressable as `script.{id}.run`, for example `script.test.run`.
3939

40+
`thread.settle` settles the open thread when it no longer needs attention. It has no default
41+
shortcut; add one from **Settings** → **Keybindings** if you want a keyboard-first settle action.
42+
4043
`filePicker.toggle` opens file search for the active project and defaults to `mod+p`.
4144
`projectSearch.toggle` searches inside the active project's files and defaults to `mod+shift+f`.
4245
Repeating either shortcut closes that search, and switching shortcuts replaces the open search.

‎packages/contracts/src/keybindings.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ it.effect("accepts dynamic script run commands", () =>
126126
}),
127127
);
128128

129+
it.effect("accepts the configurable thread settle command", () =>
130+
Effect.gen(function* () {
131+
const parsed = yield* decode(KeybindingRule, {
132+
key: "mod+shift+s",
133+
command: "thread.settle",
134+
when: "!terminalFocus",
135+
});
136+
assert.strictEqual(parsed.command, "thread.settle");
137+
}),
138+
);
139+
129140
it.effect("parses keybindings array payload", () =>
130141
Effect.gen(function* () {
131142
const parsed = yield* decode(KeybindingsConfig, [

‎packages/contracts/src/keybindings.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type ModelPickerJumpKeybindingCommand =
3737
export const THREAD_KEYBINDING_COMMANDS = [
3838
"thread.previous",
3939
"thread.next",
40+
"thread.settle",
4041
...THREAD_JUMP_KEYBINDING_COMMANDS,
4142
] as const;
4243
export type ThreadKeybindingCommand = (typeof THREAD_KEYBINDING_COMMANDS)[number];
@@ -47,7 +48,7 @@ export const MODEL_PICKER_KEYBINDING_COMMANDS = [
4748
] as const;
4849
export type ModelPickerKeybindingCommand = (typeof MODEL_PICKER_KEYBINDING_COMMANDS)[number];
4950

50-
const STATIC_KEYBINDING_COMMANDS = [
51+
export const STATIC_KEYBINDING_COMMANDS = [
5152
"sidebar.toggle",
5253
"terminal.toggle",
5354
"terminal.split",

0 commit comments

Comments
 (0)