Skip to content

Commit 4f0d54c

Browse files
t3dotggclaude
andcommitted
fix(web): settle shortcut moves to the next thread like the sidebar
The thread.settle shortcut settled the open thread but left it open. The sidebar Settle button settles and then opens the next thread. The sidebar now registers its settle action, and the shortcut uses it. Without a mounted sidebar, the shortcut settles in place as before. Fixes #16090 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3213a0c commit 4f0d54c

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ import {
242242
import { useTheme } from "../hooks/useTheme";
243243
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
244244
import { isCommandPaletteOpen } from "../commandPaletteBus";
245+
import { settleAndAdvance } from "../settleAndAdvance";
245246
import { subscribeSnapShotComposerFocus } from "../lib/desktopSnapShot";
246247
import { useMediaQuery } from "../hooks/useMediaQuery";
247248
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
@@ -8109,6 +8110,8 @@ export default function ChatView(props: ChatViewProps) {
81098110
void handleUnsettleActiveThread();
81108111
return;
81118112
}
8113+
// Same as the sidebar Settle button: settle, then open the next thread.
8114+
if (settleAndAdvance(activeThreadRef)) return;
81128115

81138116
void settleThread(activeThreadRef).then((result) => {
81148117
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ import { useAcknowledgeThreadWoke, useThreadActions } from "../hooks/useThreadAc
145145
import { useHandleNewThread } from "../hooks/useHandleNewThread";
146146
import { useTerminalFocus } from "../hooks/useTerminalFocus";
147147
import { isCommandPaletteOpen, openCommandPalette } from "../commandPaletteBus";
148+
import { registerSettleAndAdvance } from "../settleAndAdvance";
148149
import { startNewThreadFromContext } from "../lib/chatThreadActions";
149150
import { useClientSettings } from "../hooks/useSettings";
150151
import { useCopyToClipboard } from "../hooks/useCopyToClipboard";
@@ -3454,6 +3455,8 @@ export default function Sidebar() {
34543455
},
34553456
[planForwardNavigation, settleThread],
34563457
);
3458+
// The thread.settle shortcut parks the open thread through this same path.
3459+
useEffect(() => registerSettleAndAdvance(attemptSettle), [attemptSettle]);
34573460
// Post-settle navigation must skip threads settling in this same batch —
34583461
// they are all leaving the card block together. Rows that are already
34593462
// explicitly settled are skipped: nothing to do on a valid mixed selection.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2+
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
3+
import { describe, expect, it } from "vite-plus/test";
4+
5+
import { registerSettleAndAdvance, settleAndAdvance } from "./settleAndAdvance";
6+
7+
const threadRef = scopeThreadRef(
8+
EnvironmentId.make("environment-local"),
9+
ThreadId.make("thread-1"),
10+
);
11+
12+
describe("settleAndAdvance", () => {
13+
it("hands the open thread to the mounted sidebar so it can move forward", () => {
14+
const settled: ScopedThreadRef[] = [];
15+
const unregister = registerSettleAndAdvance((ref) => settled.push(ref));
16+
17+
expect(settleAndAdvance(threadRef)).toBe(true);
18+
expect(settled).toEqual([threadRef]);
19+
unregister();
20+
});
21+
22+
it("asks the caller to settle in place when no sidebar is mounted", () => {
23+
expect(settleAndAdvance(threadRef)).toBe(false);
24+
});
25+
26+
it("keeps a remounted sidebar's handler when the old one unmounts late", () => {
27+
const settledBy: string[] = [];
28+
const unregisterOld = registerSettleAndAdvance(() => settledBy.push("old"));
29+
const unregisterNew = registerSettleAndAdvance(() => settledBy.push("new"));
30+
unregisterOld();
31+
32+
expect(settleAndAdvance(threadRef)).toBe(true);
33+
expect(settledBy).toEqual(["new"]);
34+
unregisterNew();
35+
expect(settleAndAdvance(threadRef)).toBe(false);
36+
});
37+
});

‎apps/web/src/settleAndAdvance.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { ScopedThreadRef } from "@t3tools/contracts";
2+
3+
type SettleAndAdvance = (threadRef: ScopedThreadRef) => void;
4+
5+
// Only the mounted thread sidebar knows the card order that picks the next
6+
// thread, so it registers its settle action here for other entry points.
7+
let registeredSettleAndAdvance: SettleAndAdvance | null = null;
8+
9+
/**
10+
* Called by the thread sidebar while it is mounted. Returns the unregister
11+
* function, which leaves a newer registration in place.
12+
*/
13+
export function registerSettleAndAdvance(handler: SettleAndAdvance): () => void {
14+
registeredSettleAndAdvance = handler;
15+
return () => {
16+
if (registeredSettleAndAdvance === handler) registeredSettleAndAdvance = null;
17+
};
18+
}
19+
20+
/**
21+
* Settles the open thread the way the sidebar Settle button does: settle,
22+
* then move to the next thread. Used by the `thread.settle` shortcut.
23+
* Returns false when no sidebar is mounted, so the caller settles in place.
24+
*/
25+
export function settleAndAdvance(threadRef: ScopedThreadRef): boolean {
26+
if (!registeredSettleAndAdvance) return false;
27+
registeredSettleAndAdvance(threadRef);
28+
return true;
29+
}

0 commit comments

Comments
 (0)