@pierre/diffs 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +2 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +21 -11
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +3 -1
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +7 -4
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +4 -2
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +10 -5
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +3 -4
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +5 -2
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/getChangedDocumentLines.d.ts +6 -0
- package/dist/editor/getChangedDocumentLines.d.ts.map +1 -0
- package/dist/editor/getChangedDocumentLines.js +35 -0
- package/dist/editor/getChangedDocumentLines.js.map +1 -0
- package/dist/renderers/DiffHunksRenderer.d.ts +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +19 -2
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/computeVirtualFileMetrics.d.ts +2 -1
- package/dist/utils/computeVirtualFileMetrics.d.ts.map +1 -1
- package/dist/utils/computeVirtualFileMetrics.js +5 -3
- package/dist/utils/computeVirtualFileMetrics.js.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js +21 -3
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/platform.d.ts +2 -1
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/utils/platform.js +6 -1
- package/dist/utils/platform.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +8 -0
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +29 -14
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/errors.d.ts +35 -0
- package/dist/worker/errors.d.ts.map +1 -0
- package/dist/worker/errors.js +52 -0
- package/dist/worker/errors.js.map +1 -0
- package/dist/worker/index.d.ts +2 -1
- package/dist/worker/index.js +2 -1
- package/dist/worker/types.d.ts +13 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +21 -3
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +21 -3
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TextDocument, TextDocumentChange } from "./textDocument.js";
|
|
2
|
+
//#region src/editor/getChangedDocumentLines.d.ts
|
|
3
|
+
declare function getChangedDocumentLines(document: Pick<TextDocument, 'getLineText' | 'getText' | 'lineCount'>, change: TextDocumentChange): Map<number, string>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { getChangedDocumentLines };
|
|
6
|
+
//# sourceMappingURL=getChangedDocumentLines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getChangedDocumentLines.d.ts","names":[],"sources":["../../src/editor/getChangedDocumentLines.ts"],"mappings":";;iBAMgB,wBACd,UAAU,KAAK,wDACf,QAAQ,qBACP"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { linesFromFileContents } from "../utils/computeFileOffsets.js";
|
|
2
|
+
//#region src/editor/getChangedDocumentLines.ts
|
|
3
|
+
function getChangedDocumentLines(document, change) {
|
|
4
|
+
const ranges = change.changedLineChanges?.some(([, , delta]) => delta !== 0) === true ? [[change.startLine, change.endLine]] : change.changedLineRanges;
|
|
5
|
+
const lines = /* @__PURE__ */ new Map();
|
|
6
|
+
for (const [start, end] of ranges) {
|
|
7
|
+
const lastLine = Math.min(end, document.lineCount - 1);
|
|
8
|
+
if (lastLine < start) continue;
|
|
9
|
+
if (lastLine === start) {
|
|
10
|
+
lines.set(start, document.getLineText(start, true));
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const endPosition = lastLine + 1 < document.lineCount ? {
|
|
14
|
+
line: lastLine + 1,
|
|
15
|
+
character: 0
|
|
16
|
+
} : {
|
|
17
|
+
line: lastLine,
|
|
18
|
+
character: document.getLineText(lastLine).length
|
|
19
|
+
};
|
|
20
|
+
const contents = document.getText({
|
|
21
|
+
start: {
|
|
22
|
+
line: start,
|
|
23
|
+
character: 0
|
|
24
|
+
},
|
|
25
|
+
end: endPosition
|
|
26
|
+
});
|
|
27
|
+
const rangeLines = linesFromFileContents(contents);
|
|
28
|
+
for (let line = start; line <= lastLine; line++) lines.set(line, rangeLines[line - start]);
|
|
29
|
+
}
|
|
30
|
+
return lines;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { getChangedDocumentLines };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=getChangedDocumentLines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getChangedDocumentLines.js","names":[],"sources":["../../src/editor/getChangedDocumentLines.ts"],"sourcesContent":["import { linesFromFileContents } from '../utils/computeFileOffsets';\nimport type { TextDocument, TextDocumentChange } from './textDocument';\n\n// Get the current text of all lines affected by an edit, even outside the visible\n// area, so the diff keeps the same text as the editor. Adding or removing lines\n// can change the line numbers between edits, so include those lines too.\nexport function getChangedDocumentLines(\n document: Pick<TextDocument, 'getLineText' | 'getText' | 'lineCount'>,\n change: TextDocumentChange\n): Map<number, string> {\n const ranges =\n change.changedLineChanges?.some(([, , delta]) => delta !== 0) === true\n ? [[change.startLine, change.endLine]]\n : change.changedLineRanges;\n const lines = new Map<number, string>();\n for (const [start, end] of ranges) {\n const lastLine = Math.min(end, document.lineCount - 1);\n if (lastLine < start) continue;\n if (lastLine === start) {\n lines.set(start, document.getLineText(start, true));\n continue;\n }\n // Read a whole range at once to avoid searching the piece table for every\n // line. Single-line edits above keep the cheaper direct lookup.\n const endPosition =\n lastLine + 1 < document.lineCount\n ? { line: lastLine + 1, character: 0 }\n : { line: lastLine, character: document.getLineText(lastLine).length };\n const contents = document.getText({\n start: { line: start, character: 0 },\n end: endPosition,\n });\n const rangeLines = linesFromFileContents(contents);\n for (let line = start; line <= lastLine; line++) {\n lines.set(line, rangeLines[line - start]);\n }\n }\n return lines;\n}\n"],"mappings":";;AAMA,SAAgB,wBACd,UACA,QACqB;CACrB,MAAM,SACJ,OAAO,oBAAoB,MAAM,KAAK,WAAW,UAAU,CAAC,MAAM,OAC9D,CAAC,CAAC,OAAO,WAAW,OAAO,OAAO,CAAC,IACnC,OAAO;CACb,MAAM,wBAAQ,IAAI,IAAoB;CACtC,KAAK,MAAM,CAAC,OAAO,QAAQ,QAAQ;EACjC,MAAM,WAAW,KAAK,IAAI,KAAK,SAAS,YAAY,CAAC;EACrD,IAAI,WAAW,OAAO;EACtB,IAAI,aAAa,OAAO;GACtB,MAAM,IAAI,OAAO,SAAS,YAAY,OAAO,IAAI,CAAC;GAClD;EACF;EAGA,MAAM,cACJ,WAAW,IAAI,SAAS,YACpB;GAAE,MAAM,WAAW;GAAG,WAAW;EAAE,IACnC;GAAE,MAAM;GAAU,WAAW,SAAS,YAAY,QAAQ,CAAC,CAAC;EAAO;EACzE,MAAM,WAAW,SAAS,QAAQ;GAChC,OAAO;IAAE,MAAM;IAAO,WAAW;GAAE;GACnC,KAAK;EACP,CAAC;EACD,MAAM,aAAa,sBAAsB,QAAQ;EACjD,KAAK,IAAI,OAAO,OAAO,QAAQ,UAAU,QACvC,MAAM,IAAI,MAAM,WAAW,OAAO,MAAM;CAE5C;CACA,OAAO;AACT"}
|
|
@@ -133,7 +133,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
133
133
|
* row set without a line-count change — the host must escalate to a full
|
|
134
134
|
* re-render instead of its cheap refresh path.
|
|
135
135
|
*/
|
|
136
|
-
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', lineCountChangeInFlight?: boolean): boolean;
|
|
136
|
+
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', lineCountChangeInFlight?: boolean, changedDocumentLines?: ReadonlyMap<number, string>, documentLineCount?: number): boolean;
|
|
137
137
|
private applyExpansionRemap;
|
|
138
138
|
applyDocumentChange(textDocument: TextDocument<'file-diff', LAnnotation>): void;
|
|
139
139
|
private applySessionDocumentChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;;UAoJiB,iCAAiC;EAChD,mBAAmB;;UAGJ,6CAA6C,KAC5D;EAGA,kBAAkB;;UAGH;EACf;EACA,UAAU;EACV;EACA;;UAGe;EACf;EACA;EACA;;UAGe;EACf,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;;UAUL;EACf;EACA;EACA;EACA;EACA;EACA,eAAe;EACf,eAAe;;UAGA;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,UAAU;EACV,UAAU;;UAGK;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,UAAU;EACV,kBAAkB;EAClB,mBAAmB;EACnB,oBAAoB;EACpB,qBAAqB;EACrB,oBAAoB;EACpB,qBAAqB;EACrB,UAAU;EACV;EACA,SAAS;EACT,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;;cAKW,kBAAkB;EAgCpB,SAAS;UACR;UAGA;UACA;WApCD;UAED;UAIA;UAEA;UAEA;UACA;UAEA;UACA;UAGA;UAGA;UAQA;EAER,YACS,UAAS,0BACR,sBACN,YAAY,mBAAmB,yBAEzB,8CACA,gBAAgB;EASnB;EAQA;;;;;;;;;;EA4BA,iBACL,MAAM,kBACN,eAAe;;EA0EV;;;;EAWA;;;;;;;;;;EAiBA,4BAA4B;UAqC3B;MA4BG,aAAa;EAIjB;EAMA,WAAW,SAAS;EAIpB,aAAa,SAAS,QAAQ;EAI9B,WACL,eACA,WAAW,qBACX;EA0BK,gBAAgB,oBAAoB;EAIpC,uBAAuB,YAAY;;EAKnC,oBACL,eAAe,YAAY;EAKtB,mBACL,iBAAiB,mBAAmB;;;;;;;EAyB/B,kBACL,YAAY,YAAY,MAAM,oBAC9B,6BACA;
|
|
1
|
+
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;;UAoJiB,iCAAiC;EAChD,mBAAmB;;UAGJ,6CAA6C,KAC5D;EAGA,kBAAkB;;UAGH;EACf;EACA,UAAU;EACV;EACA;;UAGe;EACf;EACA;EACA;;UAGe;EACf,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;;UAUL;EACf;EACA;EACA;EACA;EACA;EACA,eAAe;EACf,eAAe;;UAGA;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,UAAU;EACV,UAAU;;UAGK;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,UAAU;EACV,kBAAkB;EAClB,mBAAmB;EACnB,oBAAoB;EACpB,qBAAqB;EACrB,oBAAoB;EACpB,qBAAqB;EACrB,UAAU;EACV;EACA,SAAS;EACT,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;;cAKW,kBAAkB;EAgCpB,SAAS;UACR;UAGA;UACA;WApCD;UAED;UAIA;UAEA;UAEA;UACA;UAEA;UACA;UAGA;UAGA;UAQA;EAER,YACS,UAAS,0BACR,sBACN,YAAY,mBAAmB,yBAEzB,8CACA,gBAAgB;EASnB;EAQA;;;;;;;;;;EA4BA,iBACL,MAAM,kBACN,eAAe;;EA0EV;;;;EAWA;;;;;;;;;;EAiBA,4BAA4B;UAqC3B;MA4BG,aAAa;EAIjB;EAMA,WAAW,SAAS;EAIpB,aAAa,SAAS,QAAQ;EAI9B,WACL,eACA,WAAW,qBACX;EA0BK,gBAAgB,oBAAoB;EAIpC,uBAAuB,YAAY;;EAKnC,oBACL,eAAe,YAAY;EAKtB,mBACL,iBAAiB,mBAAmB;;;;;;;EAyB/B,kBACL,YAAY,YAAY,MAAM,oBAC9B,6BACA,mCACA,uBAAuB,6BACvB;UAoKM;EAWD,oBACL,cAAc,0BAA0B;UAkElC;UAwBA;UAaA;YAOE,2BACR,YACC,6BAA6B;YAStB,yBACR,MACA,QACC,2BAA2B;UAetB;YAKU,iCAChB,KAAK,wBACF;YAGa,+BAChB,KAAK,wBACF;YAEK,0BAA0B;EAiDvB,yBAAyB,QAAQ;EAYvC,QAAQ,MAAM;UAmCb;EAQD,2BAA2B,KAChC;UAeM;;;;;;EA2CD,qBAAqB,MAAM,mBAAmB;UAwB7C;EAiCD,WACL,OAAM,8BACN,cAAa,cACZ;EAiJU,YACX,MAAM,kBACN,cAAa,cACZ,QAAQ;YAMD,iBACR,gBACA,oBACA,mBAAmB,sBAClB;UAeW;UAuBN;EA2CD,mBACL,MAAM,kBACN,QAAQ,kBACR,SAAS,mBACT;UAQM;UAqCA;UAgBA;UAuBA;EAaD,iBAAiB;UAIhB;UAIA;EAgjBD,cACL,6CACA,QAAQ,oBACP;EAyBI,cACL,QAAQ,mBACR,WAAU,mBACT;EAkDI,eACL,QAAQ,mBACR,eAAc;EAKT,kBACL,UAAU,kBACV;UAqBM;UAiEA;UA+DA;UASA"}
|
|
@@ -223,7 +223,7 @@ var DiffHunksRenderer = class {
|
|
|
223
223
|
* row set without a line-count change — the host must escalate to a full
|
|
224
224
|
* re-render instead of its cheap refresh path.
|
|
225
225
|
*/
|
|
226
|
-
updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
|
|
226
|
+
updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false, changedDocumentLines, documentLineCount) {
|
|
227
227
|
this.pendingStructuralRows = void 0;
|
|
228
228
|
const { renderCache } = this;
|
|
229
229
|
if (renderCache == null) return false;
|
|
@@ -234,13 +234,27 @@ var DiffHunksRenderer = class {
|
|
|
234
234
|
const pendingStructuralRows = this.pendingStructuralRows = lineCountChangeInFlight ? /* @__PURE__ */ new Map() : void 0;
|
|
235
235
|
const changedAdditionLines = [];
|
|
236
236
|
const previousAdditionLines = /* @__PURE__ */ new Map();
|
|
237
|
+
if (pendingStructuralRows == null && changedDocumentLines != null) {
|
|
238
|
+
const additionLineCount = diff.additionLines.length;
|
|
239
|
+
const canAppendFinalRow = canAppendFinalDocumentRow(diff.additionLines, documentLineCount);
|
|
240
|
+
for (const [line, text] of changedDocumentLines) {
|
|
241
|
+
if (line < 0 || line > additionLineCount || line === additionLineCount && (text === "" || !canAppendFinalRow)) continue;
|
|
242
|
+
const previous = diff.additionLines[line] ?? "";
|
|
243
|
+
if (previous !== text) {
|
|
244
|
+
diff.additionLines[line] = text;
|
|
245
|
+
changedAdditionLines.push(line);
|
|
246
|
+
previousAdditionLines.set(line, previous);
|
|
247
|
+
if (!dirtyLines.has(line)) hastLines[line] = createPlainAdditionLineElement(line, cleanLastNewline(text));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
237
251
|
for (const [line, tokens] of dirtyLines) {
|
|
238
252
|
const prevProps = hastLines[line]?.properties ?? {};
|
|
239
253
|
const lineText = tokens.map((a) => a[2]).join("");
|
|
240
254
|
const canSyncDiffLine = line < diff.additionLines.length;
|
|
241
255
|
const prevLine = canSyncDiffLine ? diff.additionLines[line] ?? "" : "";
|
|
242
256
|
const prevText = cleanLastNewline(prevLine);
|
|
243
|
-
if (pendingStructuralRows == null && canSyncDiffLine) {
|
|
257
|
+
if (pendingStructuralRows == null && canSyncDiffLine && changedDocumentLines?.has(line) !== true) {
|
|
244
258
|
diff.additionLines[line] = applyLineTextWithNewline(prevLine, lineText);
|
|
245
259
|
if (prevText !== lineText) {
|
|
246
260
|
changedAdditionLines.push(line);
|
|
@@ -1233,6 +1247,9 @@ function realignAdditionHastLines(previousLines, nextLines, hastLines, textDocum
|
|
|
1233
1247
|
for (let index = prefix; index < nextLines.length; index++) realigned[index] ??= createPlainAdditionLineElement(index, textDocument.getLineText(index));
|
|
1234
1248
|
return realigned;
|
|
1235
1249
|
}
|
|
1250
|
+
function canAppendFinalDocumentRow(additionLines, documentLineCount) {
|
|
1251
|
+
return documentLineCount === additionLines.length + 1 && additionLines.at(-1)?.endsWith("\n") === true;
|
|
1252
|
+
}
|
|
1236
1253
|
function createPlainAdditionLineElement(lineIndex, lineText, unifiedLineIndex = lineIndex, splitLineIndex = lineIndex) {
|
|
1237
1254
|
return {
|
|
1238
1255
|
type: "element",
|