refactor(app): implement canvas-based diff rendering
This commit is contained in:
@@ -135,6 +135,8 @@ describe("buildSplitDiffRows", () => {
|
||||
expect(rows[0]).toEqual({
|
||||
kind: "header",
|
||||
content: "@@ -10,1 +20,1 @@",
|
||||
hunkIndex: 0,
|
||||
lineIndex: 0,
|
||||
});
|
||||
expect(rows[1]).toMatchObject({
|
||||
kind: "pair",
|
||||
@@ -179,6 +181,8 @@ describe("buildSplitDiffRows", () => {
|
||||
expect(rows[0]).toEqual({
|
||||
kind: "header",
|
||||
content: "@@ -10,1 +10,2 @@",
|
||||
hunkIndex: 0,
|
||||
lineIndex: 0,
|
||||
});
|
||||
expect(rows[1]).toMatchObject({
|
||||
kind: "pair",
|
||||
|
||||
@@ -58,10 +58,15 @@ export interface SplitDiffDisplayLine {
|
||||
tokens?: DiffLine["tokens"];
|
||||
lineNumber: number | null;
|
||||
reviewTarget: ReviewableDiffTarget | null;
|
||||
hunkIndex: number;
|
||||
lineIndex: number;
|
||||
side: "old" | "new";
|
||||
}
|
||||
|
||||
export interface UnifiedDiffDisplayLine {
|
||||
key: string;
|
||||
hunkIndex: number;
|
||||
lineIndex: number;
|
||||
line: DiffLine;
|
||||
lineNumber: number | null;
|
||||
reviewTarget: ReviewableDiffTarget | null;
|
||||
@@ -71,6 +76,8 @@ export type SplitDiffRow =
|
||||
| {
|
||||
kind: "header";
|
||||
content: string;
|
||||
hunkIndex: number;
|
||||
lineIndex: number;
|
||||
}
|
||||
| {
|
||||
kind: "pair";
|
||||
@@ -89,6 +96,9 @@ function toSplitDisplayLine(cell: NumberedDiffCell | null): SplitDiffDisplayLine
|
||||
...(cell.line.tokens ? { tokens: cell.line.tokens } : {}),
|
||||
lineNumber: cell.lineNumber,
|
||||
reviewTarget: toReviewTarget(cell),
|
||||
hunkIndex: cell.hunkIndex,
|
||||
lineIndex: cell.lineIndex,
|
||||
side: cell.side,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -229,6 +239,8 @@ export function buildUnifiedDiffLines(file: ParsedDiffFile): UnifiedDiffDisplayL
|
||||
return buildNumberedDiffHunks(file).flatMap((hunk) =>
|
||||
hunk.lines.map((numberedLine) => ({
|
||||
key: numberedLine.key,
|
||||
hunkIndex: numberedLine.hunkIndex,
|
||||
lineIndex: numberedLine.lineIndex,
|
||||
line: numberedLine.line,
|
||||
lineNumber: numberedLine.unifiedCell?.lineNumber ?? null,
|
||||
reviewTarget: numberedLine.unifiedCell ? toReviewTarget(numberedLine.unifiedCell) : null,
|
||||
@@ -240,9 +252,12 @@ export function buildSplitDiffRows(file: ParsedDiffFile): SplitDiffRow[] {
|
||||
const rows: SplitDiffRow[] = [];
|
||||
|
||||
for (const hunk of buildNumberedDiffHunks(file)) {
|
||||
const headerLine = hunk.lines.find((line) => line.line.type === "header");
|
||||
rows.push({
|
||||
kind: "header",
|
||||
content: hunk.hunkHeader,
|
||||
hunkIndex: hunk.hunkIndex,
|
||||
lineIndex: headerLine?.lineIndex ?? 0,
|
||||
});
|
||||
|
||||
let pendingRemovals: NumberedDiffCell[] = [];
|
||||
|
||||
Reference in New Issue
Block a user