mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-18 14:43:24 +00:00
fix(ui): avoid blank streamed code line
This commit is contained in:
parent
4532bcb6fa
commit
6f06a61aa8
2 changed files with 13 additions and 1 deletions
|
|
@ -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",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue