From f2b7ac1f2b0854521b2cfe56cb686e98753c8efb Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" Date: Sat, 10 Oct 2026 12:17:58 +0200 Subject: [PATCH] fix(app): preserve highlighting within Android span limit Raise the native row cutoff to 51, derived from the five span operations per source token. Cover the boundary and an ordinary TypeScript statement that lost colors at the previous cutoff. Co-authored-by: ThePharmer --- .../source/readonly/source-lines.test.ts | 28 +++++++++++++++++-- .../source/readonly/source-lines.ts | 5 +++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/app/src/file-panels/source/readonly/source-lines.test.ts b/packages/app/src/file-panels/source/readonly/source-lines.test.ts index 81d7cb86c3..5e1317fb4c 100644 --- a/packages/app/src/file-panels/source/readonly/source-lines.test.ts +++ b/packages/app/src/file-panels/source/readonly/source-lines.test.ts @@ -79,15 +79,15 @@ describe("buildSourceLines", () => { expect(lines).toHaveLength(5402); expect(lines).toEqual(highlightCode(content, filename)); - expect(lines.some((line) => line.some((token) => token.style !== null))).toBe(true); + expect(lines.flat().some((token) => token.style !== null)).toBe(true); }); it("falls back for a dense row in the preview and full result", async () => { const filename = "data.json"; - const dense = JSON.stringify(Array.from({ length: 16 }, (_, i) => i)); + const dense = `${JSON.stringify(Array.from({ length: 25 }, (_, i) => i))} `; const content = `${dense}\n{"ok":true}\n{"ok":false}\n`; const original = highlightCode(content, filename); - expect(original[0]).toHaveLength(33); + expect(original[0]).toHaveLength(52); const [preview, full] = await build( { content, filename, presentation: "highlighted", firstLines: 1 }, 2, @@ -97,6 +97,28 @@ describe("buildSourceLines", () => { expect(full).toEqual([[{ text: dense, style: null }], ...original.slice(1)]); }); + it.each([ + ["data.json", JSON.stringify(Array.from({ length: 25 }, (_, i) => i)), 51], + [ + "ordinary.ts", + 'const values = [{ id: 0, name: "item0" }, { id: 1, name: "item1" }, { id: 2, name: "item2" }];', + 50, + ], + ])("keeps %s highlighted within the span budget", async (filename, content, tokenCount) => { + const original = highlightCode(content, filename); + const [lines] = await build({ content, filename, presentation: "highlighted" }); + + expect(original[0]).toHaveLength(tokenCount); + expect(lines[0]).toHaveLength(tokenCount); + expect(lines).toEqual(original); + }); + + it("preserves every line for unknown languages", async () => { + const content = "hello\r\n\nworld\n"; + const [lines] = await build({ content, filename: "data.unknown", presentation: "highlighted" }); + expect(lines).toEqual(content.split("\n").map((text) => [{ text, style: null }])); + }); + it("never reports lines once cancelled", async () => { let reported = false; const cancel = buildSourceLines( diff --git a/packages/app/src/file-panels/source/readonly/source-lines.ts b/packages/app/src/file-panels/source/readonly/source-lines.ts index f8bc45e8c4..5159670fa1 100644 --- a/packages/app/src/file-panels/source/readonly/source-lines.ts +++ b/packages/app/src/file-panels/source/readonly/source-lines.ts @@ -3,7 +3,10 @@ import { highlightCodeInSteps, type HighlightToken } from "@getpaseo/highlight"; /** JavaScript time per slice; the rest of the frame stays free for input and rendering. */ const SLICE_BUDGET_MS = 12; const PLAIN_LINES_PER_UNIT = 2000; -const MAX_HIGHLIGHTED_TOKENS_PER_LINE = 32; +// Android has 256 span-priority slots. A colored source fragment uses five: +// color, size, font family, line height, and the fragment marker. At most 51 +// tokens fit even when every token has a color. +const MAX_HIGHLIGHTED_TOKENS_PER_LINE = 51; /** * Splits `content` into source lines, highlighted or plain, a time slice per task so a large file