Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import type { FileDiffMetadata, Hunk, SelectionSide } from "@pierre/diffs";
export type DiffEntry = FileDiffMetadata | { note: string };
export const reservedRows = ( file: { lines?: number; stat: { insertions: number; deletions: number } }, split: boolean): number => split ? (file.lines ?? file.stat.insertions + file.stat.deletions) : (file.lines ?? file.stat.insertions + file.stat.deletions) + Math.min(file.stat.insertions, file.stat.deletions);
const sideStart = (start: number, count: number): number => (count === 0 ? start + 1 : start);
export const hiddenLine = ( hunks: readonly Hunk[], line: number, side: SelectionSide): number | undefined => { let shift = 0; for (const hunk of hunks) { const deletionFrom = sideStart(hunk.deletionStart, hunk.deletionCount); const additionFrom = sideStart(hunk.additionStart, hunk.additionCount); const from = side === "deletions" ? deletionFrom : additionFrom; const count = side === "deletions" ? hunk.deletionCount : hunk.additionCount; const delta = additionFrom - deletionFrom; if (line < from) return side === "deletions" ? line + delta : line; if (line < from + count) return undefined; shift = delta + hunk.additionCount - hunk.deletionCount; } return side === "deletions" ? line + shift : line;};
export const newSideLine = (hunks: readonly Hunk[], line: number, side: SelectionSide): number => { if (side === "additions") return line; const hidden = hiddenLine(hunks, line, side); if (hidden !== undefined) return hidden; const hunk = hunks.find( (candidate) => line >= sideStart(candidate.deletionStart, candidate.deletionCount) && line < sideStart(candidate.deletionStart, candidate.deletionCount) + candidate.deletionCount ); return hunk ? sideStart(hunk.additionStart, hunk.additionCount) : line;};