Keep diff headers and painted content on the same scroll clock while preserving native scrolling and independent per-file horizontal offsets. Complete review, selection, typography, tree, and palette parity without returning line rendering to React.
24 lines
801 B
TypeScript
24 lines
801 B
TypeScript
import { fragmentTextForRange } from "./model";
|
|
import type { DiffCell, DiffFragment } from "./types";
|
|
|
|
export interface NativeTextRun {
|
|
color: string;
|
|
left: number;
|
|
text: string;
|
|
}
|
|
|
|
/** Converts syntax ranges into disjoint positioned runs so native paints every glyph once. */
|
|
export function nativeTextRuns(cell: DiffCell, fragment: DiffFragment): NativeTextRun[] {
|
|
"worklet";
|
|
return cell.tokens.flatMap((token) => {
|
|
const start = Math.max(fragment.start, token.start);
|
|
const end = Math.min(fragment.end, token.end);
|
|
if (end <= start) return [];
|
|
let left = 0;
|
|
for (const grapheme of fragment.graphemes) {
|
|
if (grapheme.end <= start) left += grapheme.width;
|
|
}
|
|
return [{ color: token.color, left, text: fragmentTextForRange(fragment, start, end) }];
|
|
});
|
|
}
|