@pierre/diffs 1.3.0-beta.6 → 1.3.0-beta.7
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 +4 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +45 -6
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +5 -2
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +36 -23
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +126 -58
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +3 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +4 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +3 -7
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +10 -4
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +178 -49
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/editor/editor.d.ts +2 -2
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +163 -106
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/selection.d.ts +1 -1
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +87 -37
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +25 -7
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenzier.d.ts +2 -0
- package/dist/editor/tokenzier.d.ts.map +1 -1
- package/dist/editor/tokenzier.js +11 -3
- package/dist/editor/tokenzier.js.map +1 -1
- package/dist/editor/utils.d.ts +3 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +14 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +0 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/react/EditorContext.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +3 -4
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/utils/useFileDiffInstance.js +14 -15
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +29 -16
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +11 -10
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +14 -6
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/types.d.ts +59 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/areHunkDataEqual.js +1 -1
- package/dist/utils/areHunkDataEqual.js.map +1 -1
- package/dist/utils/awaitWithTimeout.d.ts +5 -0
- package/dist/utils/awaitWithTimeout.d.ts.map +1 -0
- package/dist/utils/awaitWithTimeout.js +15 -0
- package/dist/utils/awaitWithTimeout.js.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts +7 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.js +16 -0
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -0
- package/dist/utils/computeEstimatedDiffHeights.d.ts +3 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +8 -1
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/createPreElement.js +0 -1
- package/dist/utils/createPreElement.js.map +1 -1
- package/dist/utils/getDiffFileInput.d.ts +14 -0
- package/dist/utils/getDiffFileInput.d.ts.map +1 -0
- package/dist/utils/getDiffFileInput.js +24 -0
- package/dist/utils/getDiffFileInput.js.map +1 -0
- 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 +2 -0
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts +10 -0
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -0
- package/dist/utils/hydratePartialDiff.js +140 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -0
- package/dist/utils/iterateOverDiff.js +3 -3
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +1 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +26 -5
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +0 -1
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +5 -1
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +26 -4
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +7 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +78 -15
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/index.d.ts +2 -2
- package/dist/worker/types.d.ts +7 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +5 -3
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +5 -3
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,6 +18,9 @@ import { upsertHostThemeStyle } from "../utils/hostTheme.js";
|
|
|
18
18
|
import { prerenderHTMLIfNecessary } from "../utils/prerenderHTMLIfNecessary.js";
|
|
19
19
|
import { setPreNodeProperties } from "../utils/setWrapperNodeProps.js";
|
|
20
20
|
import "./web-components.js";
|
|
21
|
+
import { awaitWithTimeout } from "../utils/awaitWithTimeout.js";
|
|
22
|
+
import { getDiffFileInput } from "../utils/getDiffFileInput.js";
|
|
23
|
+
import { hydratePartialDiff } from "../utils/hydratePartialDiff.js";
|
|
21
24
|
import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
|
|
22
25
|
import { ScrollSyncManager } from "../managers/ScrollSyncManager.js";
|
|
23
26
|
import { isDiffPlainText } from "../utils/isDiffPlainText.js";
|
|
@@ -27,6 +30,9 @@ import { areHunkDataEqual } from "../utils/areHunkDataEqual.js";
|
|
|
27
30
|
import { getDiffHunksRendererOptions } from "../utils/getDiffHunksRendererOptions.js";
|
|
28
31
|
import { toHtml } from "hast-util-to-html";
|
|
29
32
|
//#region src/components/FileDiff.ts
|
|
33
|
+
function canHydrateDiff(fileDiff) {
|
|
34
|
+
return fileDiff.isPartial && (fileDiff.type === "change" || fileDiff.type === "rename-changed" || fileDiff.type === "rename-pure");
|
|
35
|
+
}
|
|
30
36
|
let instanceId = -1;
|
|
31
37
|
var FileDiff = class {
|
|
32
38
|
options;
|
|
@@ -68,6 +74,7 @@ var FileDiff = class {
|
|
|
68
74
|
additionFile;
|
|
69
75
|
fileDiff;
|
|
70
76
|
renderRange;
|
|
77
|
+
pendingFiles;
|
|
71
78
|
appliedPreAttributes;
|
|
72
79
|
lastRenderedHeaderHTML;
|
|
73
80
|
cachedHeaderHTML;
|
|
@@ -75,7 +82,8 @@ var FileDiff = class {
|
|
|
75
82
|
mounted = false;
|
|
76
83
|
enabled = true;
|
|
77
84
|
editor;
|
|
78
|
-
|
|
85
|
+
refreshViewTimeout;
|
|
86
|
+
deferSetSelection;
|
|
79
87
|
constructor(options = { theme: DEFAULT_THEMES }, workerManager, isContainerManaged = false) {
|
|
80
88
|
this.options = options;
|
|
81
89
|
this.workerManager = workerManager;
|
|
@@ -97,7 +105,7 @@ var FileDiff = class {
|
|
|
97
105
|
return new DiffHunksRenderer(this.getHunksRendererOptions(options), this.handleHighlightRender, this.workerManager);
|
|
98
106
|
}
|
|
99
107
|
getLineIndex = (lineNumber, side = "additions") => {
|
|
100
|
-
const fileDiff = this.hunksRenderer.
|
|
108
|
+
const fileDiff = this.hunksRenderer.getDiffCache() ?? this.fileDiff;
|
|
101
109
|
if (fileDiff == null) return;
|
|
102
110
|
const lastHunk = fileDiff.hunks.at(-1);
|
|
103
111
|
let targetUnifiedIndex;
|
|
@@ -192,7 +200,8 @@ var FileDiff = class {
|
|
|
192
200
|
return true;
|
|
193
201
|
}
|
|
194
202
|
setSelectedLines(range, options) {
|
|
195
|
-
this.
|
|
203
|
+
if (this.refreshViewTimeout != null) this.deferSetSelection = [range, options];
|
|
204
|
+
else this.interactionManager.setSelection(range, options);
|
|
196
205
|
}
|
|
197
206
|
flushManagers() {
|
|
198
207
|
if (!this.managersDirty || this.pre == null) {
|
|
@@ -214,6 +223,7 @@ var FileDiff = class {
|
|
|
214
223
|
this.managersDirty = false;
|
|
215
224
|
this.workerManager?.unsubscribeToThemeChanges(this);
|
|
216
225
|
this.renderRange = void 0;
|
|
226
|
+
this.pendingFiles = void 0;
|
|
217
227
|
if (!this.isContainerManaged) this.fileContainer?.remove();
|
|
218
228
|
this.fileContainer = void 0;
|
|
219
229
|
this.mounted = false;
|
|
@@ -256,17 +266,21 @@ var FileDiff = class {
|
|
|
256
266
|
this.enabled = false;
|
|
257
267
|
this.editor?.cleanUp();
|
|
258
268
|
this.editor = void 0;
|
|
259
|
-
if (this.
|
|
260
|
-
clearTimeout(this.
|
|
261
|
-
this.
|
|
269
|
+
if (this.refreshViewTimeout != null) {
|
|
270
|
+
clearTimeout(this.refreshViewTimeout);
|
|
271
|
+
this.refreshViewTimeout = void 0;
|
|
262
272
|
}
|
|
263
273
|
}
|
|
264
274
|
virtualizedSetup() {
|
|
265
275
|
this.enabled = true;
|
|
266
276
|
this.workerManager?.subscribeToThemeChanges(this);
|
|
267
277
|
}
|
|
268
|
-
hydrate(
|
|
269
|
-
|
|
278
|
+
hydrate({ fileContainer, prerenderedHTML, preventEmit = false, lineAnnotations, fileDiff, ...fileInputProps }) {
|
|
279
|
+
if (!this.enabled) throw new Error("FileDiff.hydrate: attempting to call hydrate after cleaned up");
|
|
280
|
+
if (this.fileContainer != null) throw new Error("FileDiff.hydrate: hydrate can only be called before the instance has rendered or hydrated");
|
|
281
|
+
const fileInput = getDiffFileInput(fileInputProps, "FileDiff.hydrate");
|
|
282
|
+
const oldFile = fileInput?.oldFile;
|
|
283
|
+
const newFile = fileInput?.newFile;
|
|
270
284
|
this.hydrateElements(fileContainer, prerenderedHTML);
|
|
271
285
|
if (shouldRenderCode(this.pre, hasDiffContent({
|
|
272
286
|
fileDiff,
|
|
@@ -277,14 +291,16 @@ var FileDiff = class {
|
|
|
277
291
|
oldFile,
|
|
278
292
|
newFile
|
|
279
293
|
}), this.options.disableFileHeader)) this.render({
|
|
280
|
-
...
|
|
294
|
+
...fileInputProps,
|
|
295
|
+
fileContainer,
|
|
296
|
+
lineAnnotations,
|
|
297
|
+
fileDiff,
|
|
281
298
|
preventEmit: true
|
|
282
299
|
});
|
|
283
300
|
else this.hydrationSetup({
|
|
284
301
|
fileDiff,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
lineAnnotations
|
|
302
|
+
lineAnnotations,
|
|
303
|
+
...fileInput
|
|
288
304
|
});
|
|
289
305
|
if (!preventEmit) this.emitPostRender();
|
|
290
306
|
}
|
|
@@ -332,7 +348,7 @@ var FileDiff = class {
|
|
|
332
348
|
this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;
|
|
333
349
|
this.additionFile = newFile;
|
|
334
350
|
this.deletionFile = oldFile;
|
|
335
|
-
this.fileDiff = fileDiff ?? (oldFile
|
|
351
|
+
this.fileDiff = fileDiff ?? (oldFile !== void 0 && newFile !== void 0 ? parseDiffFromFile(oldFile, newFile, this.options.parseDiffOptions) : void 0);
|
|
336
352
|
if (this.pre == null) return;
|
|
337
353
|
this.syncInteractionOptions();
|
|
338
354
|
this.hunksRenderer.hydrate(this.fileDiff);
|
|
@@ -358,30 +374,73 @@ var FileDiff = class {
|
|
|
358
374
|
};
|
|
359
375
|
expandHunk = (hunkIndex, direction, expansionLineCountOverride) => {
|
|
360
376
|
this.hunksRenderer.expandHunk(hunkIndex, direction, expansionLineCountOverride);
|
|
377
|
+
this.loadFilesIfNecessary();
|
|
361
378
|
this.rerender();
|
|
362
379
|
};
|
|
363
|
-
|
|
380
|
+
loadFilesIfNecessary() {
|
|
381
|
+
const { fileDiff, options: { loadDiffFiles } } = this;
|
|
382
|
+
if (fileDiff == null || loadDiffFiles == null || !canHydrateDiff(fileDiff) || this.pendingFiles?.fileDiff === fileDiff) return;
|
|
383
|
+
this.pendingFiles = {
|
|
384
|
+
fileDiff,
|
|
385
|
+
promise: this.loadFilesForDiff(fileDiff, loadDiffFiles)
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
async loadFilesForDiff(fileDiff, loadDiffFiles) {
|
|
389
|
+
try {
|
|
390
|
+
const files = await loadDiffFiles(fileDiff);
|
|
391
|
+
if (!this.enabled || this.fileDiff !== fileDiff) return;
|
|
392
|
+
await this.handleFilesLoaded(fileDiff, files);
|
|
393
|
+
} catch (error) {
|
|
394
|
+
if (this.options.disableErrorHandling === true) throw error;
|
|
395
|
+
console.error(error);
|
|
396
|
+
} finally {
|
|
397
|
+
if (this.pendingFiles?.fileDiff === fileDiff) this.pendingFiles = void 0;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async handleFilesLoaded(expectedDiff, files) {
|
|
401
|
+
if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) return;
|
|
402
|
+
hydratePartialDiff("merge", expectedDiff, files);
|
|
403
|
+
this.setHydratedState(files);
|
|
404
|
+
await awaitWithTimeout(() => this.primeHighlightCache(expectedDiff));
|
|
405
|
+
if (!this.enabled || this.fileDiff !== expectedDiff) return;
|
|
406
|
+
this.rerender();
|
|
407
|
+
}
|
|
408
|
+
setHydratedState(files) {
|
|
409
|
+
this.deletionFile = files.oldFile;
|
|
410
|
+
this.additionFile = files.newFile;
|
|
411
|
+
this.workerManager?.cleanUpTasks(this.hunksRenderer);
|
|
412
|
+
this.hunksRenderer.clearRenderCache();
|
|
413
|
+
}
|
|
414
|
+
render({ fileDiff, deferManagers = false, forceRender = false, preventEmit = false, lineAnnotations, fileContainer, containerWrapper, renderRange, ...fileInputProps }) {
|
|
415
|
+
const fileInput = getDiffFileInput(fileInputProps, "FileDiff.render");
|
|
416
|
+
const oldFile = fileInput?.oldFile;
|
|
417
|
+
const newFile = fileInput?.newFile;
|
|
364
418
|
if (!this.enabled) throw new Error("FileDiff.render: attempting to call render after cleaned up");
|
|
365
|
-
|
|
366
|
-
|
|
419
|
+
if (fileDiff != null && fileDiff.cacheKey === void 0) fileDiff.cacheKey = fileDiff.prevName != null ? fileDiff.prevName + ":" + fileDiff.name : fileDiff.name;
|
|
420
|
+
this.editor?.__postponeBgTokenizeToNextFrame();
|
|
421
|
+
const { collapsed = false, themeType = "system", expandUnchanged = false } = this.options;
|
|
367
422
|
const nextRenderRange = collapsed ? void 0 : renderRange;
|
|
368
423
|
const themeChanged = this.hasThemeChanged();
|
|
369
|
-
const
|
|
424
|
+
const hasFileInput = fileInput != null;
|
|
425
|
+
const filesDidChange = hasFileInput && (!areOptionalFilesEqual(oldFile, this.deletionFile) || !areOptionalFilesEqual(newFile, this.additionFile));
|
|
370
426
|
let diffDidChange = fileDiff != null && fileDiff !== this.fileDiff;
|
|
371
427
|
const annotationsChanged = lineAnnotations != null && (lineAnnotations.length > 0 || this.lineAnnotations.length > 0) ? lineAnnotations !== this.lineAnnotations : false;
|
|
372
428
|
if (!collapsed && areRenderRangesEqual(nextRenderRange, this.renderRange) && !forceRender && !annotationsChanged && !themeChanged && (fileDiff != null && fileDiff === this.fileDiff || fileDiff == null && !filesDidChange)) return this.applyCachedThemeState(themeType);
|
|
429
|
+
let nextParsedFileDiff;
|
|
430
|
+
if (fileDiff == null && hasFileInput && (filesDidChange || this.fileDiff == null)) nextParsedFileDiff = parseDiffFromFile(fileInput.oldFile, fileInput.newFile, this.options.parseDiffOptions);
|
|
373
431
|
const { renderRange: previousRenderRange } = this;
|
|
374
432
|
this.renderRange = nextRenderRange;
|
|
375
433
|
this.deletionFile = oldFile;
|
|
376
434
|
this.additionFile = newFile;
|
|
377
435
|
if (fileDiff != null) this.fileDiff = fileDiff;
|
|
378
|
-
else if (
|
|
436
|
+
else if (nextParsedFileDiff != null) {
|
|
379
437
|
diffDidChange = true;
|
|
380
|
-
this.fileDiff =
|
|
438
|
+
this.fileDiff = nextParsedFileDiff;
|
|
381
439
|
}
|
|
382
440
|
if (diffDidChange) this.cachedHeaderHTML = void 0;
|
|
383
441
|
if (lineAnnotations != null) this.setLineAnnotations(lineAnnotations);
|
|
384
442
|
if (this.fileDiff == null) return false;
|
|
443
|
+
if (expandUnchanged) this.loadFilesIfNecessary();
|
|
385
444
|
this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options));
|
|
386
445
|
this.syncInteractionOptions();
|
|
387
446
|
this.hunksRenderer.setLineAnnotations(this.lineAnnotations);
|
|
@@ -465,7 +524,7 @@ var FileDiff = class {
|
|
|
465
524
|
syncRenderViewToEditor() {
|
|
466
525
|
const editor = this.editor;
|
|
467
526
|
const fileContainer = this.fileContainer;
|
|
468
|
-
const fileDiff = this.fileDiff;
|
|
527
|
+
const fileDiff = this.hunksRenderer.getDiffCache() ?? this.fileDiff;
|
|
469
528
|
if (editor != null && fileContainer != null && fileDiff != null && !fileDiff.isPartial) this.hunksRenderer.initializeHighlighter().then((highlighter) => {
|
|
470
529
|
editor.__syncRenderView(highlighter, fileContainer, fileDiff, this.lineAnnotations, this.renderRange);
|
|
471
530
|
});
|
|
@@ -482,32 +541,34 @@ var FileDiff = class {
|
|
|
482
541
|
}
|
|
483
542
|
applyDocumentChange(textDocument, newLineAnnotations) {
|
|
484
543
|
this.hunksRenderer.applyDocumentChange(textDocument);
|
|
485
|
-
const
|
|
486
|
-
if (
|
|
487
|
-
|
|
488
|
-
|
|
544
|
+
const fileDiff = this.hunksRenderer.getDiffCache();
|
|
545
|
+
if (fileDiff != null) {
|
|
546
|
+
const cacheKey = this.fileDiff?.cacheKey;
|
|
547
|
+
if (cacheKey != null && fileDiff.cacheKey == null) fileDiff.cacheKey = cacheKey;
|
|
548
|
+
this.fileDiff = fileDiff;
|
|
549
|
+
}
|
|
489
550
|
if (newLineAnnotations !== void 0 && newLineAnnotations !== this.lineAnnotations) {
|
|
490
551
|
this.setLineAnnotations(newLineAnnotations);
|
|
491
552
|
this.hunksRenderer.setLineAnnotations(this.lineAnnotations);
|
|
492
553
|
this.renderAnnotations();
|
|
493
554
|
}
|
|
494
|
-
}
|
|
495
|
-
rerenderFromDocument(textDocument) {
|
|
496
|
-
this.hunksRenderer.applyDocumentChange(textDocument);
|
|
497
|
-
const renderDiff = this.hunksRenderer.getRenderDiff();
|
|
498
|
-
if (renderDiff != null) this.fileDiff = renderDiff;
|
|
499
|
-
this.hunksRenderer.clearRenderCache();
|
|
500
555
|
this.rerender();
|
|
556
|
+
this.interactionManager.setSelectionDirty();
|
|
501
557
|
}
|
|
502
|
-
updateRenderCache(dirtyLines, themeType, shouldRefreshView
|
|
503
|
-
this.hunksRenderer.updateRenderCache(dirtyLines, themeType
|
|
504
|
-
if (shouldRefreshView
|
|
505
|
-
if (this.
|
|
506
|
-
this.
|
|
507
|
-
this.
|
|
508
|
-
this.
|
|
509
|
-
|
|
510
|
-
|
|
558
|
+
updateRenderCache(dirtyLines, themeType, shouldRefreshView) {
|
|
559
|
+
this.hunksRenderer.updateRenderCache(dirtyLines, themeType);
|
|
560
|
+
if (shouldRefreshView) {
|
|
561
|
+
if (this.refreshViewTimeout != null) clearTimeout(this.refreshViewTimeout);
|
|
562
|
+
this.refreshViewTimeout = setTimeout(() => {
|
|
563
|
+
this.refreshViewTimeout = void 0;
|
|
564
|
+
if (this.options.diffStyle === "split") this.refreshSplitDiffView();
|
|
565
|
+
else this.refreshUnifiedDiffView();
|
|
566
|
+
if (this.deferSetSelection != null) {
|
|
567
|
+
this.interactionManager.setSelection(...this.deferSetSelection);
|
|
568
|
+
this.deferSetSelection = void 0;
|
|
569
|
+
}
|
|
570
|
+
}, 150);
|
|
571
|
+
}
|
|
511
572
|
}
|
|
512
573
|
removeRenderedCode() {
|
|
513
574
|
this.resizeManager.cleanUp();
|
|
@@ -549,12 +610,14 @@ var FileDiff = class {
|
|
|
549
610
|
this.placeHolder.style.setProperty("height", `${height}px`);
|
|
550
611
|
return true;
|
|
551
612
|
}
|
|
552
|
-
primeHighlightCache() {
|
|
553
|
-
const {
|
|
554
|
-
if (fileDiff == null || workerManager == null || isDiffPlainText(fileDiff)) return;
|
|
613
|
+
async primeHighlightCache(fileDiff = this.fileDiff) {
|
|
614
|
+
const { workerManager } = this;
|
|
615
|
+
if (fileDiff == null || workerManager == null || !workerManager.isWorkingPool() || fileDiff.cacheKey == null || isDiffPlainText(fileDiff)) return;
|
|
555
616
|
const tokenizeMaxLength = this.options.tokenizeMaxLength ?? 1e5;
|
|
556
617
|
if (Math.max(fileDiff.additionLines.length, fileDiff.deletionLines.length) > tokenizeMaxLength) return;
|
|
557
|
-
workerManager.primeDiffHighlightCache(fileDiff)
|
|
618
|
+
await workerManager.primeDiffHighlightCache(fileDiff).catch((error) => {
|
|
619
|
+
console.error(error);
|
|
620
|
+
});
|
|
558
621
|
}
|
|
559
622
|
cleanChildNodes() {
|
|
560
623
|
this.resizeManager.cleanUp();
|
|
@@ -1006,7 +1069,7 @@ var FileDiff = class {
|
|
|
1006
1069
|
this.renderPartialColumn(columns[1], additionsAST, insertPosition);
|
|
1007
1070
|
} else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition");
|
|
1008
1071
|
}
|
|
1009
|
-
|
|
1072
|
+
refreshSplitDiffView() {
|
|
1010
1073
|
if (this.options.diffStyle !== "split") return;
|
|
1011
1074
|
const hunksResult = this.hunksRenderer.renderDiff(this.fileDiff, this.renderRange);
|
|
1012
1075
|
if (hunksResult == null) return;
|
|
@@ -1026,22 +1089,23 @@ var FileDiff = class {
|
|
|
1026
1089
|
applyLineType("deletions", columns[0]);
|
|
1027
1090
|
applyLineType("additions", columns[1]);
|
|
1028
1091
|
}
|
|
1029
|
-
|
|
1092
|
+
refreshUnifiedDiffView() {
|
|
1093
|
+
if (this.options.diffStyle !== "unified") return;
|
|
1030
1094
|
const hunksResult = this.hunksRenderer.renderDiff(this.fileDiff, this.renderRange);
|
|
1031
1095
|
if (hunksResult == null) return;
|
|
1032
|
-
const columns = this.getCodeColumns(
|
|
1033
|
-
if (columns == null) return;
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1096
|
+
const columns = this.getCodeColumns("unified", this.codeUnified, this.codeDeletions, this.codeAdditions);
|
|
1097
|
+
if (columns == null || Array.isArray(columns)) return;
|
|
1098
|
+
const ast = this.hunksRenderer.renderCodeAST("unified", hunksResult);
|
|
1099
|
+
const gutterChildren = getElementChildren(ast?.[0]);
|
|
1100
|
+
const contentChildren = getElementChildren(ast?.[1]);
|
|
1101
|
+
for (const [el, astChildren] of [[columns.gutter, gutterChildren], [columns.content, contentChildren]]) if (astChildren != null) el.innerHTML = toHtml(astChildren);
|
|
1102
|
+
if (hunksResult.rowCount !== this.lastRowCount) {
|
|
1103
|
+
this.applyRowSpan("unified", columns, hunksResult.rowCount);
|
|
1104
|
+
this.lastRowCount = hunksResult.rowCount;
|
|
1105
|
+
}
|
|
1106
|
+
this.renderSeparators(hunksResult.hunkData);
|
|
1107
|
+
this.managersDirty = true;
|
|
1108
|
+
this.flushManagers();
|
|
1045
1109
|
this.syncRenderViewToEditor();
|
|
1046
1110
|
}
|
|
1047
1111
|
renderPartialColumn(column, ast, insertPosition) {
|
|
@@ -1326,6 +1390,10 @@ var FileDiff = class {
|
|
|
1326
1390
|
this.errorWrapper = void 0;
|
|
1327
1391
|
}
|
|
1328
1392
|
};
|
|
1393
|
+
function areOptionalFilesEqual(fileA, fileB) {
|
|
1394
|
+
if (fileA == null || fileB == null) return fileA == null && fileB == null;
|
|
1395
|
+
return areFilesEqual(fileA, fileB);
|
|
1396
|
+
}
|
|
1329
1397
|
function hasDiffContent({ fileDiff, oldFile, newFile }) {
|
|
1330
1398
|
return fileDiff != null && fileDiff.hunks.length > 0 || oldFile != null || newFile != null;
|
|
1331
1399
|
}
|