// Rendering a unified diff is a self-contained concern with its own size // limits, kept out of views.js so that file stays within the project's // architecture budget. // A regenerated lock file runs into tens of thousands of lines, and one element // per line freezes the window. Only the rendered view is capped. const DIFF_RENDER_LINE_LIMIT = 2000; function diffAtmosphere(diff, allLines = null) { if (!ui.selectedFile) return ""; const lines = allLines || String(diff || "").split("\n"); const additions = lines.filter( (line) => line.startsWith("+") && !line.startsWith("+++"), ).length; const removals = lines.filter( (line) => line.startsWith("-") && !line.startsWith("---"), ).length; const extension = String(ui.selectedFile).split(".").pop()?.slice(0, 8).toUpperCase() || "FILE"; return ``; } function diffLineType(line) { if (line.startsWith("+") && !line.startsWith("+++")) return "add"; if (line.startsWith("-") && !line.startsWith("---")) return "remove"; return line.startsWith("@@") ? "hunk" : ""; } function renderDiff(diff) { if (!diff) return '

No textual diff

Select another file or open the project folder for binary changes.

'; const lines = String(diff).split("\n"); const rendered = lines .slice(0, DIFF_RENDER_LINE_LIMIT) .map((line) => `${escapeHtml(line) || " "}`) .join(""); const hidden = Math.max(0, lines.length - DIFF_RENDER_LINE_LIMIT); const notice = hidden ? `… ${hidden.toLocaleString()} more line${hidden === 1 ? "" : "s"} are not shown. Copy diff and the editor still give you the complete change.` : ""; return `${rendered}${notice}${diffAtmosphere(diff, lines)}`; }