fix(ui): avoid blank streamed code line

This commit is contained in:
LukeParkerDev 2026-06-14 20:49:53 +02:00
parent 4532bcb6fa
commit 6f06a61aa8
2 changed files with 13 additions and 1 deletions

View file

@ -95,4 +95,16 @@ describe("markdown stream", () => {
language: "ts",
})
})
test("does not add a blank line before the first streamed code", () => {
const previous = project(undefined, "```ts\n", true)
const next = project(previous, `${previous.text}const x = 1`, true)
expect(next.blocks.at(-1)).toEqual({
raw: "```ts\nconst x = 1",
src: "const x = 1",
mode: "code",
language: "ts",
})
})
})

View file

@ -70,7 +70,7 @@ export function project(previous: Projection | undefined, text: string, live: bo
const suffix = text.slice(previous.text.length)
if (!suffix || tail?.mode !== "code" || tail.complete || suffix.includes("```") || suffix.includes("~~~"))
return { text, blocks: stream(text, live) }
const separator = previous.text.endsWith("\n") && !tail.src.endsWith("\n") ? "\n" : ""
const separator = tail.src.length > 0 && previous.text.endsWith("\n") && !tail.src.endsWith("\n") ? "\n" : ""
return {
text,
blocks: [