fix(web): collapse a tool call by clicking its expanded label (#11017)
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
60eff99f25
commit
502131adff
2 files changed
+62
-1
No files matched your search
@@ -1764,4 +1764,53 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain("lucide-circle-alert");
|
||||
expect(markup).toContain("text-destructive");
|
||||
});
|
||||
|
||||
it("only withholds an expanded tool-call label click while text is selected", async () => {
|
||||
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
||||
vi.stubGlobal("requestAnimationFrame", () => 0);
|
||||
vi.stubGlobal("cancelAnimationFrame", () => {});
|
||||
let renderer: ReactTestRenderer | undefined;
|
||||
try {
|
||||
await act(() => {
|
||||
renderer = create(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "entry-standalone",
|
||||
kind: "work",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
entry: {
|
||||
id: "work-standalone",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
toolCallId: "call-standalone",
|
||||
label: "Run lint",
|
||||
tone: "tool",
|
||||
itemType: "command_execution",
|
||||
command: "pnpm lint",
|
||||
toolLifecycleStatus: "completed",
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
await act(() => renderer!.root.findByProps({ "aria-expanded": false }).props.onClick());
|
||||
const label = renderer!.root.findAll(
|
||||
(node) => node.type === "span" && String(node.props.className).includes("select-text"),
|
||||
)[0];
|
||||
const stopPropagation = vi.fn();
|
||||
// Only the click that ends a selection may be withheld from the row
|
||||
// toggle; the plain click has to reach it so the label can collapse.
|
||||
for (const isCollapsed of [false, true]) {
|
||||
label!.props.onClick({
|
||||
currentTarget: { ownerDocument: { getSelection: () => ({ isCollapsed }) } },
|
||||
stopPropagation,
|
||||
});
|
||||
}
|
||||
expect(stopPropagation).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
await act(() => renderer?.unmount());
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -3172,6 +3172,18 @@ function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
|
||||
|
||||
const stopRowToggle = (e: { stopPropagation: () => void }) => e.stopPropagation();
|
||||
|
||||
/**
|
||||
* Click handler for expanded row labels, which turn text selection back on.
|
||||
* Only a click that ends a real selection is withheld from the row toggle, so
|
||||
* an ordinary click on the label still bubbles and collapses the row it opened.
|
||||
*/
|
||||
const stopRowToggleWhileSelectingText = (e: MouseEvent<HTMLElement>) => {
|
||||
const selection = e.currentTarget.ownerDocument.getSelection();
|
||||
if (selection && !selection.isCollapsed) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A1 spawn CTA: one anchored row per workflow run (or per-turn direct-spawn
|
||||
* batch). Live status is derived from the shared agent panel model at render
|
||||
@@ -3407,7 +3419,7 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
expanded ? "whitespace-pre-wrap break-words select-text" : "truncate",
|
||||
headingClass,
|
||||
)}
|
||||
onClick={expanded ? stopRowToggle : undefined}
|
||||
onClick={expanded ? stopRowToggleWhileSelectingText : undefined}
|
||||
onPointerDown={expanded ? stopRowToggle : undefined}
|
||||
>
|
||||
{previewText}
|
||||
|
||||
Reference in new issue
Block a user