@pierre/diffs 1.6.0-beta.1 → 1.6.1
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 +3 -2
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +18 -14
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +31 -9
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +165 -84
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +32 -9
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +213 -124
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +14 -4
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +35 -16
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +3 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +28 -20
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +3 -2
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +31 -24
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/platform.d.ts +1 -1
- package/dist/editor/platform.js +5 -4
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +31 -6
- package/dist/editor/selection.js.map +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +2 -1
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js +2 -2
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +8 -3
- package/dist/react/CodeView.d.ts +4 -3
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +48 -39
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/File.js +3 -3
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.js +3 -3
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.js +2 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.js +3 -3
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.js +2 -2
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/types.d.ts +4 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +1 -1
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.js +1 -1
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +29 -24
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +2 -0
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +38 -28
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useForceUpdate.d.ts +5 -0
- package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
- package/dist/react/utils/useForceUpdate.js +27 -0
- package/dist/react/utils/useForceUpdate.js.map +1 -0
- package/dist/react/utils/useNextRenderData.d.ts +9 -0
- package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
- package/dist/react/utils/useNextRenderData.js +9 -0
- package/dist/react/utils/useNextRenderData.js.map +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +62 -32
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +4 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +55 -30
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/canUseWASM.d.ts +13 -0
- package/dist/utils/canUseWASM.d.ts.map +1 -0
- package/dist/utils/canUseWASM.js +59 -0
- package/dist/utils/canUseWASM.js.map +1 -0
- package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
- package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
- package/dist/utils/getCodeViewItemRenderData.js +19 -0
- package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
- package/dist/utils/hastToHtml.d.ts +2 -2
- package/dist/utils/hastToHtml.js +2 -2
- package/dist/utils/hastToHtml.js.map +1 -1
- package/dist/utils/hydratePartialDiff.js +4 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +24 -4
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderTokenLines.d.ts +6 -1
- package/dist/utils/renderTokenLines.d.ts.map +1 -1
- package/dist/utils/renderTokenLines.js +4 -0
- package/dist/utils/renderTokenLines.js.map +1 -1
- package/dist/utils/resolveRegion.js +20 -10
- package/dist/utils/resolveRegion.js.map +1 -1
- package/dist/utils/tokenStyle.d.ts +5 -1
- package/dist/utils/tokenStyle.d.ts.map +1 -1
- package/dist/utils/tokenStyle.js +5 -1
- package/dist/utils/tokenStyle.js.map +1 -1
- package/dist/utils/tokensToHtml.d.ts +5 -2
- package/dist/utils/tokensToHtml.d.ts.map +1 -1
- package/dist/utils/tokensToHtml.js +5 -2
- package/dist/utils/tokensToHtml.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +2 -2
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +7 -3
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +12 -0
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +99 -21
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/{highlights-sAHlxqlf.js → highlights-CpZm9DAR.js} +2 -2
- package/dist/worker/{highlights-sAHlxqlf.js.map → highlights-CpZm9DAR.js.map} +1 -1
- package/dist/worker/{shiki-Bx2JpdqZ.js → shiki-Ci4cdHsM.js} +2 -2
- package/dist/worker/{shiki-Bx2JpdqZ.js.map → shiki-Ci4cdHsM.js.map} +1 -1
- package/dist/worker/{stream-tokenizer-YZ6M1qSx.js → stream-tokenizer-DK9xp5M5.js} +8 -5
- package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
- package/dist/worker/types.d.ts +11 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +4 -4
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +12 -3
- package/dist/worker/worker.js.map +1 -1
- package/package.json +28 -30
- package/dist/worker/stream-tokenizer-YZ6M1qSx.js.map +0 -1
|
@@ -17,6 +17,7 @@ import { getFiletypeFromFileName } from "../utils/getFiletypeFromFileName.js";
|
|
|
17
17
|
import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
|
|
18
18
|
import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
19
19
|
import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
|
|
20
|
+
import { isHandledWorkerPoolError } from "../worker/errors.js";
|
|
20
21
|
import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
|
|
21
22
|
import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
|
|
22
23
|
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
@@ -39,7 +40,6 @@ var DiffHunksRenderer = class {
|
|
|
39
40
|
onRenderUpdate;
|
|
40
41
|
workerManager;
|
|
41
42
|
__id = `diff-hunks-renderer:${++instanceId}`;
|
|
42
|
-
highlighter;
|
|
43
43
|
diff;
|
|
44
44
|
expandedHunks = /* @__PURE__ */ new Map();
|
|
45
45
|
deletionAnnotations = {};
|
|
@@ -54,7 +54,6 @@ var DiffHunksRenderer = class {
|
|
|
54
54
|
this.annotationSlotName = annotationSlotName;
|
|
55
55
|
this.onRenderUpdate = onRenderUpdate;
|
|
56
56
|
this.workerManager = workerManager;
|
|
57
|
-
if (workerManager?.isWorkingPool() !== true) this.highlighter = getHighlighterIfLoaded({ theme: options.theme ?? DEFAULT_THEMES });
|
|
58
57
|
}
|
|
59
58
|
cleanUp() {
|
|
60
59
|
this.endEditSession();
|
|
@@ -64,7 +63,6 @@ var DiffHunksRenderer = class {
|
|
|
64
63
|
this.onRenderUpdate = void 0;
|
|
65
64
|
}
|
|
66
65
|
recycle() {
|
|
67
|
-
this.highlighter = void 0;
|
|
68
66
|
this.diff = void 0;
|
|
69
67
|
if (this.editSessionActive) {
|
|
70
68
|
if (this.renderCache != null) this.renderCache.renderRange = void 0;
|
|
@@ -150,7 +148,9 @@ var DiffHunksRenderer = class {
|
|
|
150
148
|
workerManager.evictDiffFromCache(diff.cacheKey);
|
|
151
149
|
return workerManager.primeDiffHighlightCache(diff).then(() => {
|
|
152
150
|
this.applyRefreshedResult(diff, workerManager.getDiffResultCache(diff));
|
|
153
|
-
}).catch((error) =>
|
|
151
|
+
}).catch((error) => {
|
|
152
|
+
if (!isHandledWorkerPoolError(error)) this.onHighlightError(error);
|
|
153
|
+
});
|
|
154
154
|
}
|
|
155
155
|
return this.asyncHighlight(diff).then((fresh) => this.applyRefreshedResult(diff, fresh)).catch((error) => this.onHighlightError(error));
|
|
156
156
|
}
|
|
@@ -244,6 +244,7 @@ var DiffHunksRenderer = class {
|
|
|
244
244
|
const previous = diff.additionLines[line] ?? "";
|
|
245
245
|
if (previous !== text) {
|
|
246
246
|
diff.additionLines[line] = text;
|
|
247
|
+
diff.additionCharacterCount += text.length - previous.length;
|
|
247
248
|
changedAdditionLines.push(line);
|
|
248
249
|
previousAdditionLines.set(line, previous);
|
|
249
250
|
if (!dirtyLines.has(line)) hastLines[line] = createPlainAdditionLineElement(line, cleanLastNewline(text));
|
|
@@ -257,7 +258,9 @@ var DiffHunksRenderer = class {
|
|
|
257
258
|
const prevLine = canSyncDiffLine ? diff.additionLines[line] ?? "" : "";
|
|
258
259
|
const prevText = cleanLastNewline(prevLine);
|
|
259
260
|
if (pendingStructuralRows == null && canSyncDiffLine && changedDocumentLines?.has(line) !== true) {
|
|
260
|
-
|
|
261
|
+
const nextLine = applyLineTextWithNewline(prevLine, lineText);
|
|
262
|
+
diff.additionLines[line] = nextLine;
|
|
263
|
+
diff.additionCharacterCount += nextLine.length - prevLine.length;
|
|
261
264
|
if (prevText !== lineText) {
|
|
262
265
|
changedAdditionLines.push(line);
|
|
263
266
|
previousAdditionLines.set(line, prevLine);
|
|
@@ -308,7 +311,7 @@ var DiffHunksRenderer = class {
|
|
|
308
311
|
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
309
312
|
regionsChanged = true;
|
|
310
313
|
} else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
|
|
311
|
-
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
|
|
314
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, diff.additionCharacterCount, this.options.parseDiffOptions));
|
|
312
315
|
regionsChanged = true;
|
|
313
316
|
} else {
|
|
314
317
|
const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
|
|
@@ -332,7 +335,9 @@ var DiffHunksRenderer = class {
|
|
|
332
335
|
const result = renderCache?.result;
|
|
333
336
|
if (diff.isPartial) throw new Error("Could not apply document change for partial diff");
|
|
334
337
|
const { additionLines: previousAdditionLines } = diff;
|
|
335
|
-
|
|
338
|
+
const { lines, characterCount } = getEditorDocumentLines(textDocument);
|
|
339
|
+
diff.additionLines = lines;
|
|
340
|
+
diff.additionCharacterCount = characterCount;
|
|
336
341
|
if (result != null) result.code.additionLines = realignAdditionHastLines(previousAdditionLines, diff.additionLines, result.code.additionLines, textDocument);
|
|
337
342
|
if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
338
343
|
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
@@ -348,7 +353,7 @@ var DiffHunksRenderer = class {
|
|
|
348
353
|
const { parseDiffOptions } = this.options;
|
|
349
354
|
const rawLines = diff.additionLines;
|
|
350
355
|
if (shouldTopAlignAdditionRecompute(diff, rawLines)) {
|
|
351
|
-
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, rawLines, parseDiffOptions));
|
|
356
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, rawLines, diff.additionCharacterCount, parseDiffOptions));
|
|
352
357
|
return;
|
|
353
358
|
}
|
|
354
359
|
this.applyExpansionRemap(rebuildSessionHunks(diff, parseDiffOptions, (index) => previousAdditionLines[index]));
|
|
@@ -405,18 +410,16 @@ var DiffHunksRenderer = class {
|
|
|
405
410
|
useCSSClasses
|
|
406
411
|
};
|
|
407
412
|
}
|
|
408
|
-
|
|
409
|
-
|
|
413
|
+
initializeHighlighter() {
|
|
414
|
+
return getSharedHighlighter(getHighlighterOptions(this.computedLangs, {
|
|
410
415
|
theme: this.getLocalHighlightTheme(),
|
|
411
416
|
preferredHighlighter: resolvePreferredHighlighter(this.workerManager, this.options)
|
|
412
417
|
}));
|
|
413
|
-
return this.highlighter;
|
|
414
418
|
}
|
|
415
419
|
hydrate(diff) {
|
|
416
420
|
if (diff == null) return;
|
|
417
421
|
this.diff = diff;
|
|
418
422
|
const { options } = this.getRenderOptions(diff);
|
|
419
|
-
this.highlighter = getHighlighterIfLoaded({ theme: this.getLocalHighlightTheme() });
|
|
420
423
|
const massiveDiff = isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
421
424
|
let cache = this.workerManager?.getDiffResultCache(diff);
|
|
422
425
|
if (cache != null && !areDiffRenderOptionsEqual(options, cache.options)) cache = void 0;
|
|
@@ -428,15 +431,24 @@ var DiffHunksRenderer = class {
|
|
|
428
431
|
result: massiveDiff ? void 0 : cache?.result,
|
|
429
432
|
renderRange: void 0
|
|
430
433
|
};
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
+
const workerManager = this.getHighlightWorkerManager(diff);
|
|
435
|
+
if (workerManager != null) {
|
|
436
|
+
if (this.renderCache.result == null && !massiveDiff) workerManager.highlightDiffAST(this, this.diff);
|
|
437
|
+
} else if (getHighlighterIfLoaded({ theme: this.getLocalHighlightTheme() }) == null) {
|
|
434
438
|
this.computedLangs = getDiffLanguages(diff);
|
|
435
439
|
this.initializeHighlighter().catch((error) => {
|
|
436
440
|
if (!(error instanceof HighlighterDisposedError)) this.onHighlightError(error);
|
|
437
441
|
});
|
|
438
442
|
}
|
|
439
443
|
}
|
|
444
|
+
getHighlightWorkerManager(diff) {
|
|
445
|
+
const { editSessionActive, workerManager } = this;
|
|
446
|
+
return !editSessionActive && workerManager?.isWorkingPool() === true && !workerManager.shouldHighlightOnMainThread(diff) ? workerManager : void 0;
|
|
447
|
+
}
|
|
448
|
+
cacheHighlightResult(diff, renderResult) {
|
|
449
|
+
const { editSessionActive, workerManager } = this;
|
|
450
|
+
if (!editSessionActive && workerManager?.isWorkingPool() === true) workerManager.setDiffResultCache(diff.cacheKey, renderResult);
|
|
451
|
+
}
|
|
440
452
|
getLocalHighlightTheme() {
|
|
441
453
|
return this.workerManager?.getDiffRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
|
|
442
454
|
}
|
|
@@ -497,10 +509,10 @@ var DiffHunksRenderer = class {
|
|
|
497
509
|
canRenderDiff(diff, options, forcePlainText) {
|
|
498
510
|
const { renderCache } = this;
|
|
499
511
|
if (renderCache == null || areDiffTargetsEqual(renderCache.diff, diff)) return true;
|
|
500
|
-
if (forcePlainText) return renderCache.result == null && renderCache.hydrated !== true || this.workerManager?.isWorkingPool() === true
|
|
512
|
+
if (forcePlainText) return renderCache.result == null && renderCache.hydrated !== true || this.workerManager?.isWorkingPool() === true && !this.workerManager.shouldHighlightOnMainThread(diff) || getHighlighterIfLoaded({ theme: options.theme }) != null;
|
|
501
513
|
if (renderCache.result == null && renderCache.hydrated !== true) return true;
|
|
502
|
-
if (
|
|
503
|
-
return
|
|
514
|
+
if (this.getHighlightWorkerManager(diff) != null) return !renderCache.highlighted;
|
|
515
|
+
return getHighlighterIfLoaded({ theme: options.theme }) != null;
|
|
504
516
|
}
|
|
505
517
|
renderDiff(diff = this.diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
506
518
|
this.diff = diff;
|
|
@@ -529,28 +541,29 @@ var DiffHunksRenderer = class {
|
|
|
529
541
|
};
|
|
530
542
|
const hasContent = diff.additionLines.length > 0 || diff.deletionLines.length > 0;
|
|
531
543
|
const forcePlainText = !hasContent || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
532
|
-
this.highlighter = getHighlighterIfLoaded();
|
|
533
544
|
const canRenderDiff = this.canRenderDiff(diff, options, forcePlainText);
|
|
534
545
|
const newContent = !areDiffTargetsEqual(diff, this.renderCache.diff);
|
|
535
546
|
const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
|
|
536
|
-
|
|
547
|
+
const workerManager = this.getHighlightWorkerManager(diff);
|
|
548
|
+
if (workerManager != null) {
|
|
537
549
|
const preserveHydratedContent = this.renderCache.result == null && this.renderCache.highlighted && !forcePlainText && !newContent && isDefaultRenderRange(renderRange);
|
|
538
550
|
if (canRenderDiff && !preserveHydratedContent && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
|
|
539
551
|
this.renderCache.diff = diff;
|
|
540
552
|
this.renderCache.options = options;
|
|
541
553
|
this.renderCache.highlighted = false;
|
|
542
|
-
if (this.renderCache.result == null || newContent || newRenderRange || forceHighlight) this.renderCache.result =
|
|
554
|
+
if (this.renderCache.result == null || newContent || newRenderRange || forceHighlight) this.renderCache.result = workerManager.getPlainDiffAST(diff, renderRange.startingLine, renderRange.totalLines, isDefaultRenderRange(renderRange) ? true : expandUnchanged ? true : this.expandedHunks, collapsedContextThreshold);
|
|
543
555
|
this.renderCache.renderRange = renderRange;
|
|
544
556
|
}
|
|
545
|
-
if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight))
|
|
557
|
+
if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight)) workerManager.highlightDiffAST(this, diff);
|
|
546
558
|
} else {
|
|
547
559
|
this.computedLangs = getDiffLanguages(diff);
|
|
548
|
-
const
|
|
549
|
-
const
|
|
560
|
+
const highlighter = getHighlighterIfLoaded();
|
|
561
|
+
const hasThemes = highlighter != null && areThemesAttached(options.theme, highlighter);
|
|
562
|
+
const hasLangs = highlighter != null && areLanguagesAttached(this.computedLangs, highlighter);
|
|
550
563
|
const canHighlight = !forcePlainText && hasLangs;
|
|
551
564
|
const lazyLineAST = Number.isFinite(renderRange.totalLines);
|
|
552
|
-
if (canRenderDiff &&
|
|
553
|
-
const { result, options } = this.renderDiffWithHighlighter(diff,
|
|
565
|
+
if (canRenderDiff && highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
|
|
566
|
+
const { result, options } = this.renderDiffWithHighlighter(diff, highlighter, forcePlainText || !hasLangs, lazyLineAST);
|
|
554
567
|
this.renderCache = {
|
|
555
568
|
diff,
|
|
556
569
|
options,
|
|
@@ -558,8 +571,16 @@ var DiffHunksRenderer = class {
|
|
|
558
571
|
result,
|
|
559
572
|
renderRange: void 0
|
|
560
573
|
};
|
|
574
|
+
if (canHighlight) this.cacheHighlightResult(diff, {
|
|
575
|
+
result,
|
|
576
|
+
options
|
|
577
|
+
});
|
|
561
578
|
}
|
|
562
579
|
if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(diff, lazyLineAST).then(({ result, options }) => {
|
|
580
|
+
if (!forcePlainText) this.cacheHighlightResult(diff, {
|
|
581
|
+
result,
|
|
582
|
+
options
|
|
583
|
+
});
|
|
563
584
|
this.applyHighlightResult(diff, result, options, !forcePlainText);
|
|
564
585
|
}).catch((error) => {
|
|
565
586
|
if (!(error instanceof HighlighterDisposedError)) this.onHighlightError(error);
|
|
@@ -588,10 +609,11 @@ var DiffHunksRenderer = class {
|
|
|
588
609
|
async asyncHighlight(diff, lazyLineAST = false) {
|
|
589
610
|
const forcePlainText = isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
590
611
|
this.computedLangs = forcePlainText ? ["text"] : getDiffLanguages(diff);
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
612
|
+
let highlighter = getHighlighterIfLoaded();
|
|
613
|
+
const hasThemes = highlighter != null && areThemesAttached(this.getLocalHighlightTheme(), highlighter);
|
|
614
|
+
const hasLangs = forcePlainText || highlighter != null && areLanguagesAttached(this.computedLangs, highlighter);
|
|
615
|
+
if (highlighter == null || !hasThemes || !hasLangs) highlighter = await this.initializeHighlighter();
|
|
616
|
+
return this.renderDiffWithHighlighter(diff, highlighter, forcePlainText, lazyLineAST);
|
|
595
617
|
}
|
|
596
618
|
renderDiffWithHighlighter(diff, highlighter, forcePlainText = false, lazyLineAST = false) {
|
|
597
619
|
const { options } = this.getRenderOptions(diff);
|
|
@@ -1281,8 +1303,16 @@ function createPlainAdditionLineElement(lineIndex, lineText, unifiedLineIndex =
|
|
|
1281
1303
|
}
|
|
1282
1304
|
function getEditorDocumentLines(textDocument) {
|
|
1283
1305
|
const lines = [];
|
|
1284
|
-
|
|
1285
|
-
|
|
1306
|
+
let characterCount = 0;
|
|
1307
|
+
for (let line = 0; line < textDocument.lineCount; line++) {
|
|
1308
|
+
const text = textDocument.getLineText(line, true);
|
|
1309
|
+
lines.push(text);
|
|
1310
|
+
characterCount += text.length;
|
|
1311
|
+
}
|
|
1312
|
+
return {
|
|
1313
|
+
lines,
|
|
1314
|
+
characterCount
|
|
1315
|
+
};
|
|
1286
1316
|
}
|
|
1287
1317
|
function getDiffLanguages(diff) {
|
|
1288
1318
|
if (diff.lang != null) return [diff.lang];
|