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 <metastallion@gmail.com>
This commit is contained in:
paseo-bot[bot]
2026-11-21 18:45:42 +00:00
co-authored by ThePharmer
parent 8b8f405d2e
commit f2b7ac1f2b
2 changed files with 29 additions and 4 deletions
@@ -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(
@@ -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