Skip to content

Commit 502131a

Browse files
maria-rcksclaude
andauthored
fix(web): collapse a tool call by clicking its expanded label (pingdotgg#11017)
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 60eff99 commit 502131a

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,4 +1764,53 @@ describe("MessagesTimeline", () => {
17641764
expect(markup).toContain("lucide-circle-alert");
17651765
expect(markup).toContain("text-destructive");
17661766
});
1767+
1768+
it("only withholds an expanded tool-call label click while text is selected", async () => {
1769+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
1770+
vi.stubGlobal("requestAnimationFrame", () => 0);
1771+
vi.stubGlobal("cancelAnimationFrame", () => {});
1772+
let renderer: ReactTestRenderer | undefined;
1773+
try {
1774+
await act(() => {
1775+
renderer = create(
1776+
<MessagesTimeline
1777+
{...buildProps()}
1778+
timelineEntries={[
1779+
{
1780+
id: "entry-standalone",
1781+
kind: "work",
1782+
createdAt: MESSAGE_CREATED_AT,
1783+
entry: {
1784+
id: "work-standalone",
1785+
createdAt: MESSAGE_CREATED_AT,
1786+
toolCallId: "call-standalone",
1787+
label: "Run lint",
1788+
tone: "tool",
1789+
itemType: "command_execution",
1790+
command: "pnpm lint",
1791+
toolLifecycleStatus: "completed",
1792+
},
1793+
},
1794+
]}
1795+
/>,
1796+
);
1797+
});
1798+
await act(() => renderer!.root.findByProps({ "aria-expanded": false }).props.onClick());
1799+
const label = renderer!.root.findAll(
1800+
(node) => node.type === "span" && String(node.props.className).includes("select-text"),
1801+
)[0];
1802+
const stopPropagation = vi.fn();
1803+
// Only the click that ends a selection may be withheld from the row
1804+
// toggle; the plain click has to reach it so the label can collapse.
1805+
for (const isCollapsed of [false, true]) {
1806+
label!.props.onClick({
1807+
currentTarget: { ownerDocument: { getSelection: () => ({ isCollapsed }) } },
1808+
stopPropagation,
1809+
});
1810+
}
1811+
expect(stopPropagation).toHaveBeenCalledTimes(1);
1812+
} finally {
1813+
await act(() => renderer?.unmount());
1814+
}
1815+
});
17671816
});

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3172,6 +3172,18 @@ function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
31723172

31733173
const stopRowToggle = (e: { stopPropagation: () => void }) => e.stopPropagation();
31743174

3175+
/**
3176+
* Click handler for expanded row labels, which turn text selection back on.
3177+
* Only a click that ends a real selection is withheld from the row toggle, so
3178+
* an ordinary click on the label still bubbles and collapses the row it opened.
3179+
*/
3180+
const stopRowToggleWhileSelectingText = (e: MouseEvent<HTMLElement>) => {
3181+
const selection = e.currentTarget.ownerDocument.getSelection();
3182+
if (selection && !selection.isCollapsed) {
3183+
e.stopPropagation();
3184+
}
3185+
};
3186+
31753187
/**
31763188
* A1 spawn CTA: one anchored row per workflow run (or per-turn direct-spawn
31773189
* batch). Live status is derived from the shared agent panel model at render
@@ -3407,7 +3419,7 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
34073419
expanded ? "whitespace-pre-wrap break-words select-text" : "truncate",
34083420
headingClass,
34093421
)}
3410-
onClick={expanded ? stopRowToggle : undefined}
3422+
onClick={expanded ? stopRowToggleWhileSelectingText : undefined}
34113423
onPointerDown={expanded ? stopRowToggle : undefined}
34123424
>
34133425
{previewText}

0 commit comments

Comments
 (0)