Skip to content

Commit 75ba985

Browse files
committed
fix(webview): render expanded task header text as markdown with consistent scrollbar
1 parent f780647 commit 75ba985

12 files changed

Lines changed: 1184 additions & 10 deletions

‎pnpm-lock.yaml‎

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
"react-use": "^17.5.1",
6868
"react-virtuoso": "^4.7.13",
6969
"rehype-katex": "^7.0.1",
70+
"remark-breaks": "^4.0.0",
7071
"remark-gfm": "^4.0.1",
7172
"remark-math": "^6.0.0",
73+
"remark-parse": "^11.0.0",
7274
"remove-markdown": "^0.6.4",
7375
"shell-quote": "^1.8.2",
7476
"shiki": "^3.2.1",
@@ -78,6 +80,7 @@
7880
"tailwind-merge": "^3.0.0",
7981
"tailwindcss": "^4.0.0",
8082
"tailwindcss-animate": "^1.0.7",
83+
"unified": "^11.0.5",
8184
"unist-util-visit": "^5.0.0",
8285
"use-sound": "^5.0.0",
8386
"vscode-material-icons": "^0.1.1",

‎webview-ui/playwright/gallery/stories.tsx‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,66 @@ export const stories: Record<string, Story> = {
181181
</div>
182182
)
183183
},
184+
"task-header-markdown": async () => {
185+
const [{ AppProviders }, { default: TaskHeader }] = await Promise.all([
186+
import("../AppProviders"),
187+
import("@/components/chat/TaskHeader"),
188+
])
189+
// Representative user-authored prompt: heading, bold, inline code, a
190+
// bullet list, an external link, soft breaks (single newlines), and the
191+
// three mention kinds (path, @problems, @terminal). The length keeps the
192+
// expanded prompt box (max-h-80) overflowing so the scrollbar surface is
193+
// captured by the snapshot.
194+
const prompt = [
195+
"# Refactor the billing module",
196+
"",
197+
"Update the invoice total in `src/billing/invoice.ts` so that",
198+
"refunds apply before tax. Keep the **public API** stable while",
199+
"moving the rounding logic into a shared helper.",
200+
"",
201+
"- Recalculate totals in `calculateInvoiceTotal`",
202+
"- Emit the warning listed in @problems after the first failing assertion",
203+
"- Re-run the demo script with @terminal",
204+
"- Keep the behavior documented in the [billing design notes](https://example.com/docs/billing)",
205+
"",
206+
"Watch the edge cases in @/src/billing/invoice.ts, especially",
207+
"the package-style exports and the cached total memo.",
208+
"",
209+
"The refactor should ship behind a feature flag and the",
210+
"rollback path must stay one command away.",
211+
].join("\n")
212+
const ts = 1755000000000
213+
return (
214+
<AppProviders
215+
initialState={{
216+
apiConfiguration: { apiProvider: "anthropic", apiModelId: "claude-sonnet-4-5" },
217+
currentTaskItem: {
218+
id: "task-header-markdown",
219+
number: 1,
220+
ts,
221+
task: prompt,
222+
tokensIn: 1248,
223+
tokensOut: 342,
224+
totalCost: 0.0084,
225+
status: "active",
226+
},
227+
}}>
228+
<div className="w-[480px] bg-vscode-editor-background">
229+
<TaskHeader
230+
task={{ type: "say", ts, text: prompt, images: [] }}
231+
tokensIn={1248}
232+
tokensOut={342}
233+
totalCost={0.0084}
234+
cacheWrites={120}
235+
cacheReads={8032}
236+
contextTokens={24576}
237+
buttonsDisabled={false}
238+
handleCondenseContext={() => undefined}
239+
/>
240+
</div>
241+
</AppProviders>
242+
)
243+
},
184244
"ui-settings": async () => {
185245
const { UISettingsStory } = await import("@/components/settings/__tests__/UISettings.visual.fixture")
186246
return <UISettingsStory />

‎webview-ui/src/components/chat/TaskHeader.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { Mention } from "./Mention"
2929
import { TodoListDisplay } from "./TodoListDisplay"
3030
import { LucideIconButton } from "./LucideIconButton"
3131

32+
import MarkdownBlock from "../common/MarkdownBlock"
33+
3234
export interface TaskHeaderProps {
3335
task: ClineMessage
3436
tokensIn: number
@@ -163,7 +165,11 @@ const TaskHeader = ({
163165
e.target.closest('[role="button"]') ||
164166
e.target.closest("[data-radix-popper-content-wrapper]") ||
165167
e.target.closest("img") ||
166-
e.target.tagName === "IMG")
168+
// Stryker disable next-line ConditionalExpression,StringLiteral: a click on the <img> itself is already caught by closest("img") above; the tagName backstop adds no distinct behavior
169+
e.target.tagName === "IMG" ||
170+
e.target.closest("a") ||
171+
// Stryker disable next-line ConditionalExpression,StringLiteral: a click on the <a> itself is already caught by closest("a") above; the tagName backstop adds no distinct behavior
172+
e.target.tagName === "A")
167173
) {
168174
return
169175
}
@@ -324,13 +330,13 @@ const TaskHeader = ({
324330
className="text-vscode-font-size overflow-y-auto break-words break-anywhere relative">
325331
<div
326332
ref={textRef}
327-
className="overflow-auto max-h-80 whitespace-pre-wrap break-words break-anywhere cursor-text py-0.5"
333+
className="scrollable overflow-auto max-h-80 break-words break-anywhere cursor-text py-0.5"
328334
style={{
329335
display: "-webkit-box",
330336
WebkitLineClamp: "unset",
331337
WebkitBoxOrient: "vertical",
332338
}}>
333-
<Mention text={task.text} />
339+
<MarkdownBlock markdown={task.text ?? ""} mentions breaks />
334340
</div>
335341
</div>
336342
{task.images && task.images.length > 0 && <Thumbnails images={task.images} />}

‎webview-ui/src/components/chat/__tests__/TaskHeader.spec.tsx‎

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,179 @@ describe("TaskHeader", () => {
330330
expect(screen.getByText("25%")).toBeInTheDocument()
331331
})
332332
})
333+
334+
describe("Expanded task text markdown rendering", () => {
335+
it("shows raw source while collapsed and formatted markdown when expanded", async () => {
336+
const { container } = renderTaskHeader({
337+
task: { type: "say", ts: Date.now(), text: "**bold** and `code`", images: [] },
338+
})
339+
340+
// Collapsed state renders the raw task text (no markdown formatting yet).
341+
expect(screen.getByText("**bold** and `code`")).toBeInTheDocument()
342+
expect(container.querySelector("strong")).toBeNull()
343+
344+
// Expand the header by clicking the collapsed title.
345+
fireEvent.click(screen.getByText("**bold** and `code`"))
346+
347+
// Expanded state applies markdown: **bold** becomes <strong>, `code` becomes <code>.
348+
const bold = await screen.findByText("bold")
349+
expect(bold.tagName).toBe("STRONG")
350+
expect(container.querySelector("code")?.textContent).toBe("code")
351+
352+
// The raw markdown source must not be displayed verbatim in the expanded view.
353+
expect(screen.queryByText("**bold** and `code`")).not.toBeInTheDocument()
354+
})
355+
356+
it("uses the shared scrollable style for the expanded prompt box", () => {
357+
const { container } = renderTaskHeader({
358+
task: { type: "say", ts: Date.now(), text: "prompt", images: [] },
359+
})
360+
361+
// Expand the header.
362+
fireEvent.click(screen.getByText("prompt"))
363+
364+
// The prompt box must use the VS Code-style .scrollable scrollbar (hover-reveal),
365+
// not a default always-visible Chromium scrollbar, so it matches the message list.
366+
const scrollBox = container.querySelector(".scrollable")
367+
expect(scrollBox).not.toBeNull()
368+
expect(scrollBox?.className).toContain("max-h-80")
369+
})
370+
371+
it("renders headings and lists in the expanded view", async () => {
372+
const { container } = renderTaskHeader({
373+
task: {
374+
type: "say",
375+
ts: Date.now(),
376+
text: "# Heading\n- item one\n- item two",
377+
images: [],
378+
},
379+
})
380+
381+
// Expand via the header container (the raw multi-line title is not a stable text target).
382+
fireEvent.click(container.querySelector(".cursor-pointer")!)
383+
384+
const heading = await screen.findByRole("heading")
385+
expect(heading.textContent).toBe("Heading")
386+
expect(container.querySelector("ul li")).not.toBeNull()
387+
})
388+
389+
it("does not collapse the panel when a rendered markdown link is clicked", async () => {
390+
const { container } = renderTaskHeader({
391+
task: {
392+
type: "say",
393+
ts: Date.now(),
394+
text: "**bold** [example](https://example.com)",
395+
images: [],
396+
},
397+
})
398+
399+
// Expand the header.
400+
fireEvent.click(screen.getByText("**bold** [example](https://example.com)"))
401+
const link = await screen.findByRole("link", { name: "example" })
402+
403+
// Clicking a rendered link must not toggle isTaskExpanded (the header click
404+
// handler ignores anchor targets), so the expanded content stays visible.
405+
fireEvent.click(link)
406+
expect(container.querySelector("strong")).not.toBeNull()
407+
})
408+
409+
it("keeps context mentions clickable in the expanded markdown view", async () => {
410+
const { container } = renderTaskHeader({
411+
task: {
412+
type: "say",
413+
ts: Date.now(),
414+
text: "Inspect @/src/file.ts, @problems, and @terminal.",
415+
images: [],
416+
},
417+
})
418+
419+
// Expand via the header container because the collapsed title contains split mention spans.
420+
fireEvent.click(container.querySelector(".cursor-pointer")!)
421+
await screen.findByText(/Inspect/, { exact: false })
422+
423+
const mentions = container.querySelectorAll("span.mention-context-highlight")
424+
expect(mentions).toHaveLength(3)
425+
expect(mentions[0].textContent).toBe("@/src/file.ts")
426+
expect(mentions[1].textContent).toBe("@problems")
427+
expect(mentions[2].textContent).toBe("@terminal")
428+
429+
fireEvent.click(mentions[0])
430+
expect(mockPostMessage).toHaveBeenCalledWith({ type: "openMention", text: "/src/file.ts" })
431+
432+
// The mention click must not bubble to the header toggle (the mention handler
433+
// stops propagation), so the expanded markdown stays rendered after the
434+
// mention is opened instead of the panel collapsing.
435+
expect(screen.getByText(/Inspect/, { exact: false })).toBeInTheDocument()
436+
expect(container.querySelectorAll("span.mention-context-highlight")).toHaveLength(3)
437+
})
438+
439+
it("keeps single newlines as line breaks in a plain-text prompt", async () => {
440+
const { container } = renderTaskHeader({
441+
task: { type: "say", ts: Date.now(), text: "Fix the login bug\nIt crashes on startup", images: [] },
442+
})
443+
444+
// Expand via the header container (the raw multi-line title is not a stable text target).
445+
fireEvent.click(container.querySelector(".cursor-pointer")!)
446+
447+
// Inexact match: the soft break splits the paragraph into text<br>text, so no
448+
// single element's full text equals the first line.
449+
await screen.findByText(/Fix the login bug/, { exact: false })
450+
451+
// The previous expanded view rendered plain text with whitespace-pre-wrap, so a
452+
// single newline was always a line break. The markdown pipeline collapses soft
453+
// breaks to spaces per CommonMark unless remark-breaks is enabled, so the header
454+
// must keep the newline structural (<br>) instead of reflowing the prompt into
455+
// one paragraph.
456+
const paragraph = container.querySelector(".scrollable p")
457+
expect(paragraph).not.toBeNull()
458+
expect(paragraph?.querySelector("br")).not.toBeNull()
459+
expect(paragraph?.textContent).toBe("Fix the login bugIt crashes on startup")
460+
})
461+
462+
it("still parses markdown headings and lists while keeping newlines inside them", async () => {
463+
const { container } = renderTaskHeader({
464+
task: {
465+
type: "say",
466+
ts: Date.now(),
467+
text: "# Heading\n- item one\n continued line\n- item two",
468+
images: [],
469+
},
470+
})
471+
472+
// Expand via the header container (the raw multi-line title is not a stable text target).
473+
fireEvent.click(container.querySelector(".cursor-pointer")!)
474+
475+
const heading = await screen.findByRole("heading")
476+
expect(heading.textContent).toBe("Heading")
477+
478+
// Markdown still parses (the # line is a heading, the - lines are list items)...
479+
const items = container.querySelectorAll(".scrollable li")
480+
expect(items).toHaveLength(2)
481+
482+
// ...and the soft break inside the first item renders as a line break.
483+
expect(items[0]?.querySelector("br")).not.toBeNull()
484+
expect(items[0]?.textContent).toBe("item onecontinued line")
485+
expect(items[1]?.textContent).toBe("item two")
486+
})
487+
488+
it("renders an empty prompt without crashing", () => {
489+
const { container } = renderTaskHeader({
490+
// `text` is optional on ClineMessage; omit it to exercise the empty-prompt path.
491+
task: { type: "say", ts: Date.now(), images: [] },
492+
})
493+
494+
// No title text to click, so expand via the header container itself.
495+
fireEvent.click(container.querySelector(".cursor-pointer")!)
496+
497+
// The empty prompt renders nothing but must not crash; the rest of the
498+
// expanded header (cost row) is still present.
499+
expect(screen.getByText("$0.05")).toBeInTheDocument()
500+
501+
// The expanded text area stays empty: a missing prompt must not render
502+
// placeholder content into the markdown container.
503+
const textArea = container.querySelector(".scrollable")
504+
expect(textArea).not.toBeNull()
505+
expect(textArea?.textContent).toBe("")
506+
})
507+
})
333508
})

0 commit comments

Comments
 (0)