diff --git a/web/src/structuredRender.test.ts b/web/src/structuredRender.test.ts index 0b6e485..622739f 100644 --- a/web/src/structuredRender.test.ts +++ b/web/src/structuredRender.test.ts @@ -315,8 +315,8 @@ describe("buildTranscriptRow: tool diffs", () => { (el.querySelector(".st-tool-head") as HTMLButtonElement).click(); const diff = el.querySelector(".st-diff") as HTMLElement; expect(diff).not.toBeNull(); - expect(diff.querySelector(".st-ln-add")!.textContent).toBe("c"); - expect(diff.querySelector(".st-ln-del")!.textContent).toBe("b"); + expect(diff.querySelector(".st-ln-add")!.textContent).toBe("+ c"); + expect(diff.querySelector(".st-ln-del")!.textContent).toBe("- b"); }); it("gives the diff its own horizontally-scrolling container", () => { diff --git a/web/src/structuredRender.ts b/web/src/structuredRender.ts index 31ef0a4..6b8e7f2 100644 --- a/web/src/structuredRender.ts +++ b/web/src/structuredRender.ts @@ -223,15 +223,16 @@ function buildDiffBlock(diff: { path: string; oldText?: string | null; newText: wrap.appendChild(label); const scroller = el("div", "st-diff"); const pre = document.createElement("pre"); - for (const line of computeDiffLines(diff.oldText, diff.newText)) { + const lines = computeDiffLines(diff.oldText, diff.newText); + const prefixes: Record = { add: "+ ", del: "- ", ctx: " ", hunk: "", eof: "" }; + for (const line of lines) { const span = document.createElement("span"); span.className = `st-ln st-ln-${line.kind}`; - span.textContent = line.text; + span.textContent = (prefixes[line.kind] ?? "") + line.text; pre.appendChild(span); - pre.appendChild(document.createTextNode("\n")); } scroller.appendChild(pre); - makeCopyable(scroller, pre.textContent ?? "", "diff"); + makeCopyable(scroller, lines.map((l) => (prefixes[l.kind] ?? "") + l.text).join("\n"), "diff"); wrap.appendChild(scroller); return wrap; } diff --git a/web/src/styles.css b/web/src/styles.css index 1528074..38898c2 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -2990,6 +2990,7 @@ input.leaf-rename:focus { display: block; white-space: pre; padding: 0 var(--sp-3); + line-height: 1.4; } .st-ln-add {