@pierre/diffs 1.3.6 → 1.4.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 +115 -68
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +189 -59
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +79 -15
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +244 -66
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +101 -21
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +432 -102
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.js +1 -1
- package/dist/components/UnresolvedFile.d.ts +2 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +17 -7
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +142 -53
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +15 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +186 -96
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/edit/index.d.ts +7 -4
- package/dist/edit/index.js +5 -1
- package/dist/editor/EditStateManager.d.ts +56 -0
- package/dist/editor/EditStateManager.d.ts.map +1 -0
- package/dist/editor/EditStateManager.js +135 -0
- package/dist/editor/EditStateManager.js.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +7 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js +16 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js.map +1 -0
- package/dist/editor/editPrediction.d.ts +76 -0
- package/dist/editor/editPrediction.d.ts.map +1 -0
- package/dist/editor/editPrediction.js +365 -0
- package/dist/editor/editPrediction.js.map +1 -0
- package/dist/editor/editStack.d.ts +19 -40
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js +67 -4
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +118 -29
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +1108 -384
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/languages.d.ts +3 -3
- package/dist/editor/languages.d.ts.map +1 -1
- package/dist/editor/languages.js.map +1 -1
- package/dist/editor/lineAnnotations.d.ts +3 -3
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +16 -7
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +2 -2
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +2 -2
- package/dist/editor/matchBrackets.d.ts.map +1 -1
- package/dist/editor/matchBrackets.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +2 -2
- package/dist/editor/searchPanel.js +1 -1
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +32 -23
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +3 -3
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +3 -3
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/textDocument.d.ts +11 -8
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +28 -5
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textDocumentChangeTransaction.d.ts +15 -0
- package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -0
- package/dist/editor/textDocumentChangeTransaction.js +12 -0
- package/dist/editor/textDocumentChangeTransaction.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +5 -0
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +10 -0
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +1 -1
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/editor/types.d.ts +267 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/editor/types.js +0 -0
- package/dist/editor/utils.d.ts +2 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +4 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +6 -2
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js +7 -3
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/themes/areThemesAttached.js +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +22 -21
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +7 -0
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +36 -25
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +15 -14
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +8 -11
- package/dist/react/EditContext.d.ts.map +1 -1
- package/dist/react/EditContext.js +2 -9
- package/dist/react/EditContext.js.map +1 -1
- package/dist/react/File.d.ts +10 -6
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +8 -4
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +10 -5
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +8 -4
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +8 -5
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +8 -12
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +7 -4
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +8 -4
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +3 -3
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +8 -5
- package/dist/react/types.d.ts +46 -9
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +14 -12
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +2 -2
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +14 -12
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +2 -2
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +22 -10
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +112 -22
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +15 -9
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +84 -25
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +30 -15
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +172 -109
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +27 -11
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +141 -67
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
- package/dist/shiki-stream/tokenizer.js +2 -1
- package/dist/shiki-stream/tokenizer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +21 -21
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +1 -1
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.d.ts +6 -6
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/ssr/preloadPatchFile.d.ts +4 -4
- package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +13 -263
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/appendItems.d.ts +5 -0
- package/dist/utils/appendItems.d.ts.map +1 -0
- package/dist/utils/appendItems.js +8 -0
- package/dist/utils/appendItems.js.map +1 -0
- package/dist/utils/areDiffTargetsEqual.js +1 -1
- package/dist/utils/areDiffTargetsEqual.js.map +1 -1
- package/dist/utils/areFileTargetsEqual.d.ts +7 -0
- package/dist/utils/areFileTargetsEqual.d.ts.map +1 -0
- package/dist/utils/areFileTargetsEqual.js +8 -0
- package/dist/utils/areFileTargetsEqual.js.map +1 -0
- package/dist/utils/areManagedSnapshotsEqual.d.ts +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/areOptionsEqual.d.ts +3 -3
- package/dist/utils/areOptionsEqual.d.ts.map +1 -1
- package/dist/utils/areOptionsEqual.js.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +3 -2
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.js +8 -5
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -1
- package/dist/utils/composeCacheKey.d.ts +6 -0
- package/dist/utils/composeCacheKey.d.ts.map +1 -0
- package/dist/utils/composeCacheKey.js +10 -0
- package/dist/utils/composeCacheKey.js.map +1 -0
- package/dist/utils/editSessionAnnotations.d.ts +69 -0
- package/dist/utils/editSessionAnnotations.d.ts.map +1 -0
- package/dist/utils/editSessionAnnotations.js +64 -0
- package/dist/utils/editSessionAnnotations.js.map +1 -0
- package/dist/utils/editSessionHunks.d.ts +5 -3
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.js +7 -5
- package/dist/utils/editSessionHunks.js.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts +1 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
- package/dist/utils/hydratePartialDiff.js +2 -1
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/lineAnnotationIdentity.d.ts +16 -0
- package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -0
- package/dist/utils/lineAnnotationIdentity.js +17 -0
- package/dist/utils/lineAnnotationIdentity.js.map +1 -0
- package/dist/utils/parseDiffFromFile.d.ts +2 -2
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +6 -6
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +6 -3
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +34 -9
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +6 -5
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +7 -4
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/trimPatchContext.d.ts.map +1 -1
- package/dist/utils/trimPatchContext.js +3 -2
- package/dist/utils/trimPatchContext.js.map +1 -1
- package/dist/utils/updateDiffHunks.js +1 -1
- package/dist/utils/virtualDiffLayout.js +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +4 -3
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +44 -6
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/types.d.ts +5 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +14 -6
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +14 -6
- package/dist/worker/worker.js.map +1 -1
- package/package.json +9 -1
- package/dist/editor/stateStorage.d.ts +0 -15
- package/dist/editor/stateStorage.d.ts.map +0 -1
- package/dist/editor/stateStorage.js +0 -65
- package/dist/editor/stateStorage.js.map +0 -1
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { DEFAULT_EXPANDED_REGION, DEFAULT_RENDER_RANGE, DEFAULT_THEMES, DEFAULT_TOKENIZE_MAX_LENGTH } from "../constants.js";
|
|
2
|
-
import { cleanLastNewline } from "../utils/cleanLastNewline.js";
|
|
3
|
-
import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
|
|
4
|
-
import { recomputeDiffHunksForEdit, recomputeEmptyDocumentDiff, recomputeTopAlignedAdditionDiff, shouldTopAlignAdditionRecompute, updateDiffHunks } from "../utils/updateDiffHunks.js";
|
|
5
|
-
import { applySessionChangedLines, rebuildSessionHunks, remapExpandedHunksForRegionChange } from "../utils/editSessionHunks.js";
|
|
6
|
-
import { getFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
|
|
7
|
-
import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
|
|
8
2
|
import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
|
|
9
|
-
import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
|
|
10
3
|
import { areThemesAttached } from "../highlighter/themes/areThemesAttached.js";
|
|
4
|
+
import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
|
|
5
|
+
import { getFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
|
|
6
|
+
import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
|
|
11
7
|
import { applyLineTextWithNewline } from "../utils/applyLineTextWithNewline.js";
|
|
12
8
|
import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
|
|
13
9
|
import { createAnnotationElement } from "../utils/createAnnotationElement.js";
|
|
@@ -17,15 +13,19 @@ import { createPreElement } from "../utils/createPreElement.js";
|
|
|
17
13
|
import { getFiletypeFromFileName } from "../utils/getFiletypeFromFileName.js";
|
|
18
14
|
import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
|
|
19
15
|
import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
16
|
+
import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
|
|
20
17
|
import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
|
|
18
|
+
import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
|
|
21
19
|
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
20
|
+
import { cleanLastNewline } from "../utils/cleanLastNewline.js";
|
|
22
21
|
import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
|
|
23
22
|
import { createEmptyRowBuffer } from "../utils/createEmptyRowBuffer.js";
|
|
24
23
|
import { createNoNewlineElement } from "../utils/createNoNewlineElement.js";
|
|
25
24
|
import { createSeparator } from "../utils/createSeparator.js";
|
|
25
|
+
import { recomputeDiffHunksForEdit, recomputeEmptyDocumentDiff, recomputeTopAlignedAdditionDiff, shouldTopAlignAdditionRecompute, updateDiffHunks } from "../utils/updateDiffHunks.js";
|
|
26
|
+
import { applySessionChangedLines, rebuildSessionHunks, remapExpandedHunksForRegionChange } from "../utils/editSessionHunks.js";
|
|
26
27
|
import { getHunkSeparatorSlotName } from "../utils/getHunkSeparatorSlotName.js";
|
|
27
28
|
import { getTotalLineCountFromHunks } from "../utils/getTotalLineCountFromHunks.js";
|
|
28
|
-
import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
|
|
29
29
|
import { isDiffPlainText } from "../utils/isDiffPlainText.js";
|
|
30
30
|
import { renderDiffWithHighlighter } from "../utils/renderDiffWithHighlighter.js";
|
|
31
31
|
import { toHtml } from "hast-util-to-html";
|
|
@@ -33,6 +33,7 @@ import { toHtml } from "hast-util-to-html";
|
|
|
33
33
|
let instanceId = -1;
|
|
34
34
|
var DiffHunksRenderer = class {
|
|
35
35
|
options;
|
|
36
|
+
annotationSlotName;
|
|
36
37
|
onRenderUpdate;
|
|
37
38
|
workerManager;
|
|
38
39
|
__id = `diff-hunks-renderer:${++instanceId}`;
|
|
@@ -43,9 +44,12 @@ var DiffHunksRenderer = class {
|
|
|
43
44
|
additionAnnotations = {};
|
|
44
45
|
computedLang = "text";
|
|
45
46
|
renderCache;
|
|
47
|
+
pendingHighlightResult;
|
|
48
|
+
pendingStructuralRows;
|
|
46
49
|
editSessionActive = false;
|
|
47
|
-
constructor(options = { theme: DEFAULT_THEMES }, onRenderUpdate, workerManager) {
|
|
50
|
+
constructor(options = { theme: DEFAULT_THEMES }, annotationSlotName = getLineAnnotationName, onRenderUpdate, workerManager) {
|
|
48
51
|
this.options = options;
|
|
52
|
+
this.annotationSlotName = annotationSlotName;
|
|
49
53
|
this.onRenderUpdate = onRenderUpdate;
|
|
50
54
|
this.workerManager = workerManager;
|
|
51
55
|
if (workerManager?.isWorkingPool() !== true) this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES) ? getHighlighterIfLoaded() : void 0;
|
|
@@ -69,22 +73,51 @@ var DiffHunksRenderer = class {
|
|
|
69
73
|
* Enter edit-session mode: hunk updates preserve the current region
|
|
70
74
|
* skeleton instead of recomputing hunks, and rendering happens locally
|
|
71
75
|
* with the token transformer forced on (worker-pool requests/results are
|
|
72
|
-
* suspended for this renderer).
|
|
73
|
-
*
|
|
74
|
-
*
|
|
76
|
+
* suspended for this renderer). When the session was freshly cloned from
|
|
77
|
+
* `externalDiff`, compatible highlighted markup is detached from its external
|
|
78
|
+
* cache owner so the editor can reuse it without mutating shared data. An
|
|
79
|
+
* empty additions document gets one row for the editor's caret.
|
|
75
80
|
*/
|
|
76
|
-
beginEditSession() {
|
|
81
|
+
beginEditSession(diff, externalDiff) {
|
|
82
|
+
const { editSessionActive: wasAlreadyActive, renderCache } = this;
|
|
77
83
|
this.editSessionActive = true;
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
if (!wasAlreadyActive) this.pendingHighlightResult = void 0;
|
|
85
|
+
this.diff = diff;
|
|
86
|
+
if (!diff.isPartial && diff.additionLines.length === 0) {
|
|
80
87
|
Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
81
88
|
this.markEditSessionPass(diff);
|
|
82
89
|
this.clearRenderCache();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (renderCache == null) return;
|
|
93
|
+
if (wasAlreadyActive && renderCache.diff === diff) return;
|
|
94
|
+
const { options } = this.getRenderOptions(diff);
|
|
95
|
+
const cacheBelongsToSession = renderCache.diff === diff;
|
|
96
|
+
const cacheBelongsToExternal = externalDiff != null && areDiffTargetsEqual(renderCache.diff, externalDiff);
|
|
97
|
+
const { result } = renderCache;
|
|
98
|
+
if (!renderCache.highlighted || result == null || !areDiffRenderOptionsEqual(renderCache.options, options) || !cacheBelongsToSession && !cacheBelongsToExternal) {
|
|
99
|
+
this.clearRenderCache();
|
|
100
|
+
return;
|
|
83
101
|
}
|
|
102
|
+
if (cacheBelongsToSession) return;
|
|
103
|
+
this.renderCache = {
|
|
104
|
+
diff,
|
|
105
|
+
options,
|
|
106
|
+
highlighted: true,
|
|
107
|
+
result: {
|
|
108
|
+
...result,
|
|
109
|
+
code: {
|
|
110
|
+
...result.code,
|
|
111
|
+
additionLines: [...result.code.additionLines]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
renderRange: renderCache.renderRange
|
|
115
|
+
};
|
|
84
116
|
}
|
|
85
117
|
/** Leave edit-session mode. The exit recompute is the host's concern. */
|
|
86
118
|
endEditSession() {
|
|
87
119
|
this.editSessionActive = false;
|
|
120
|
+
this.pendingHighlightResult = void 0;
|
|
88
121
|
}
|
|
89
122
|
/**
|
|
90
123
|
* Ensures that the DOM is compatible with editor render updates
|
|
@@ -93,20 +126,17 @@ var DiffHunksRenderer = class {
|
|
|
93
126
|
return this.renderCache?.options.useTokenTransformer === true && this.renderCache.highlighted && this.renderCache.result != null;
|
|
94
127
|
}
|
|
95
128
|
/**
|
|
96
|
-
* Re-highlights the current diff in the background and
|
|
97
|
-
* result
|
|
98
|
-
* session
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* interim paint drops highlighting.
|
|
129
|
+
* Re-highlights the current diff in the background and stages the fresh
|
|
130
|
+
* result for the next render. Needed after an edit session's exit recompute:
|
|
131
|
+
* session passes plain-fill shifted lines in the cached result, and the
|
|
132
|
+
* recompute mutates the keyless session diff in place, so object identity
|
|
133
|
+
* alone would otherwise treat the stale highlight as current forever. The
|
|
134
|
+
* current result — content-correct, mostly highlighted — keeps rendering
|
|
135
|
+
* until the fresh one is promoted, so no interim paint drops highlighting.
|
|
104
136
|
*/
|
|
105
137
|
refreshHighlightedResult() {
|
|
106
|
-
const { renderCache } = this;
|
|
107
|
-
if (renderCache == null ||
|
|
108
|
-
const { diff } = renderCache;
|
|
109
|
-
const { workerManager } = this;
|
|
138
|
+
const { diff, renderCache, workerManager } = this;
|
|
139
|
+
if (diff == null || renderCache == null || !areDiffTargetsEqual(renderCache.diff, diff) || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength())) return Promise.resolve();
|
|
110
140
|
if (!this.editSessionActive && workerManager?.isWorkingPool() === true && diff.cacheKey != null) {
|
|
111
141
|
workerManager.evictDiffFromCache(diff.cacheKey);
|
|
112
142
|
return workerManager.primeDiffHighlightCache(diff).then(() => {
|
|
@@ -116,15 +146,15 @@ var DiffHunksRenderer = class {
|
|
|
116
146
|
return this.asyncHighlight(diff).then((fresh) => this.applyRefreshedResult(diff, fresh)).catch((error) => this.onHighlightError(error));
|
|
117
147
|
}
|
|
118
148
|
applyRefreshedResult(diff, fresh) {
|
|
119
|
-
|
|
120
|
-
|
|
149
|
+
const { diff: currentDiff, renderCache } = this;
|
|
150
|
+
if (fresh == null || currentDiff == null || renderCache == null || !areDiffTargetsEqual(currentDiff, diff) || !areDiffTargetsEqual(renderCache.diff, diff) || this.editSessionActive) return;
|
|
151
|
+
const { options } = this.getRenderOptions(currentDiff);
|
|
121
152
|
if (!areDiffRenderOptionsEqual(options, fresh.options)) return;
|
|
122
|
-
this.
|
|
123
|
-
diff,
|
|
153
|
+
this.pendingHighlightResult = {
|
|
154
|
+
diff: currentDiff,
|
|
124
155
|
options: fresh.options,
|
|
125
156
|
highlighted: true,
|
|
126
|
-
result: fresh.result
|
|
127
|
-
renderRange: void 0
|
|
157
|
+
result: fresh.result
|
|
128
158
|
};
|
|
129
159
|
this.onRenderUpdate?.();
|
|
130
160
|
}
|
|
@@ -132,9 +162,9 @@ var DiffHunksRenderer = class {
|
|
|
132
162
|
return this.renderCache?.diff ?? this.diff;
|
|
133
163
|
}
|
|
134
164
|
clearRenderCache() {
|
|
135
|
-
const renderCache = this.renderCache;
|
|
136
165
|
this.renderCache = void 0;
|
|
137
|
-
|
|
166
|
+
this.pendingHighlightResult = void 0;
|
|
167
|
+
this.pendingStructuralRows = void 0;
|
|
138
168
|
}
|
|
139
169
|
setOptions(options) {
|
|
140
170
|
this.options = options;
|
|
@@ -187,11 +217,14 @@ var DiffHunksRenderer = class {
|
|
|
187
217
|
* re-render instead of its cheap refresh path.
|
|
188
218
|
*/
|
|
189
219
|
updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
|
|
190
|
-
|
|
191
|
-
const {
|
|
220
|
+
this.pendingStructuralRows = void 0;
|
|
221
|
+
const { renderCache } = this;
|
|
222
|
+
if (renderCache == null) return false;
|
|
223
|
+
const { result, diff } = renderCache;
|
|
192
224
|
if (result == null) return false;
|
|
193
225
|
if (diff.isPartial) throw new Error("Could not update render cache for partial diff");
|
|
194
226
|
const hastLines = result.code.additionLines;
|
|
227
|
+
const pendingStructuralRows = this.pendingStructuralRows = lineCountChangeInFlight ? /* @__PURE__ */ new Map() : void 0;
|
|
195
228
|
const changedAdditionLines = [];
|
|
196
229
|
const previousAdditionLines = /* @__PURE__ */ new Map();
|
|
197
230
|
for (const [line, tokens] of dirtyLines) {
|
|
@@ -200,14 +233,14 @@ var DiffHunksRenderer = class {
|
|
|
200
233
|
const canSyncDiffLine = line < diff.additionLines.length;
|
|
201
234
|
const prevLine = canSyncDiffLine ? diff.additionLines[line] ?? "" : "";
|
|
202
235
|
const prevText = cleanLastNewline(prevLine);
|
|
203
|
-
if (canSyncDiffLine) {
|
|
236
|
+
if (pendingStructuralRows == null && canSyncDiffLine) {
|
|
204
237
|
diff.additionLines[line] = applyLineTextWithNewline(prevLine, lineText);
|
|
205
238
|
if (prevText !== lineText) {
|
|
206
239
|
changedAdditionLines.push(line);
|
|
207
240
|
previousAdditionLines.set(line, prevLine);
|
|
208
241
|
}
|
|
209
242
|
}
|
|
210
|
-
|
|
243
|
+
const row = {
|
|
211
244
|
type: "element",
|
|
212
245
|
tagName: "div",
|
|
213
246
|
properties: {
|
|
@@ -242,56 +275,64 @@ var DiffHunksRenderer = class {
|
|
|
242
275
|
};
|
|
243
276
|
})
|
|
244
277
|
};
|
|
278
|
+
if (pendingStructuralRows != null) pendingStructuralRows.set(line, row);
|
|
279
|
+
else hastLines[line] = row;
|
|
245
280
|
}
|
|
246
281
|
let regionsChanged = false;
|
|
247
|
-
if (changedAdditionLines.length > 0) if (this.editSessionActive &&
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
regionsChanged = change != null;
|
|
260
|
-
}
|
|
261
|
-
} else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
282
|
+
if (changedAdditionLines.length > 0) if (this.editSessionActive) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
283
|
+
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
284
|
+
regionsChanged = true;
|
|
285
|
+
} else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
|
|
286
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
|
|
287
|
+
regionsChanged = true;
|
|
288
|
+
} else {
|
|
289
|
+
const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
|
|
290
|
+
this.applyExpansionRemap(change);
|
|
291
|
+
regionsChanged = change != null;
|
|
292
|
+
}
|
|
293
|
+
else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
262
294
|
result.baseThemeType = themeType;
|
|
263
|
-
|
|
295
|
+
renderCache.isDirty = true;
|
|
264
296
|
return regionsChanged;
|
|
265
297
|
}
|
|
266
298
|
applyExpansionRemap(change) {
|
|
267
299
|
if (change != null) this.expandedHunks = remapExpandedHunksForRegionChange(this.expandedHunks, change);
|
|
268
300
|
}
|
|
269
301
|
applyDocumentChange(textDocument) {
|
|
270
|
-
|
|
271
|
-
|
|
302
|
+
const { pendingStructuralRows, renderCache } = this;
|
|
303
|
+
this.pendingStructuralRows = void 0;
|
|
304
|
+
if (renderCache == null) return;
|
|
305
|
+
const { diff, result } = renderCache;
|
|
272
306
|
if (result == null) return;
|
|
273
307
|
if (diff.isPartial) throw new Error("Could not apply document change for partial diff");
|
|
274
308
|
const { additionLines: previousAdditionLines } = diff;
|
|
275
|
-
diff.additionLines = getEditorDocumentLines(textDocument
|
|
309
|
+
diff.additionLines = getEditorDocumentLines(textDocument);
|
|
276
310
|
result.code.additionLines = realignAdditionHastLines(previousAdditionLines, diff.additionLines, result.code.additionLines, textDocument);
|
|
277
311
|
if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
278
|
-
|
|
312
|
+
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
279
313
|
result.code.additionLines[0] = createPlainAdditionLineElement(0, textDocument.getLineText(0));
|
|
280
|
-
this.markEditSessionPass(diff);
|
|
281
314
|
} else if (this.editSessionActive) this.applySessionDocumentChange(diff);
|
|
282
315
|
else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
|
|
283
|
-
|
|
316
|
+
if (pendingStructuralRows != null) {
|
|
317
|
+
for (const [line, row] of pendingStructuralRows) if (line < result.code.additionLines.length) result.code.additionLines[line] = row;
|
|
318
|
+
}
|
|
319
|
+
renderCache.isDirty = true;
|
|
284
320
|
}
|
|
285
321
|
applySessionDocumentChange(diff) {
|
|
286
322
|
const { parseDiffOptions } = this.options;
|
|
287
323
|
const rawLines = diff.additionLines;
|
|
288
324
|
if (shouldTopAlignAdditionRecompute(diff, rawLines)) {
|
|
289
|
-
|
|
290
|
-
this.markEditSessionPass(diff);
|
|
325
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, rawLines, parseDiffOptions));
|
|
291
326
|
return;
|
|
292
327
|
}
|
|
293
328
|
this.applyExpansionRemap(rebuildSessionHunks(diff, parseDiffOptions));
|
|
294
329
|
}
|
|
330
|
+
applyRecomputePreservingSessionType(diff, update) {
|
|
331
|
+
const sessionType = this.editSessionActive ? diff.type : void 0;
|
|
332
|
+
Object.assign(diff, update);
|
|
333
|
+
if (sessionType != null) diff.type = sessionType;
|
|
334
|
+
this.markEditSessionPass(diff);
|
|
335
|
+
}
|
|
295
336
|
markEditSessionPass(diff) {
|
|
296
337
|
if (!this.editSessionActive) return;
|
|
297
338
|
diff.editSessionDirty = true;
|
|
@@ -354,6 +395,7 @@ var DiffHunksRenderer = class {
|
|
|
354
395
|
if (cache != null && !areDiffRenderOptionsEqual(options, cache.options)) cache = void 0;
|
|
355
396
|
this.renderCache ??= {
|
|
356
397
|
diff,
|
|
398
|
+
hydrated: true,
|
|
357
399
|
highlighted: !massiveDiff && !isDiffPlainText(diff),
|
|
358
400
|
options,
|
|
359
401
|
result: massiveDiff ? void 0 : cache?.result,
|
|
@@ -410,17 +452,42 @@ var DiffHunksRenderer = class {
|
|
|
410
452
|
forceHighlight: false
|
|
411
453
|
};
|
|
412
454
|
}
|
|
413
|
-
|
|
414
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Returns the diff that the next synchronous render can commit without
|
|
457
|
+
* changing the renderer's current diff or render cache. Components use this
|
|
458
|
+
* to prepare state that must match the following DOM render.
|
|
459
|
+
*/
|
|
460
|
+
getDiffForNextRender(diff) {
|
|
461
|
+
const { options } = this.getRenderOptions(diff);
|
|
462
|
+
if (this.getReadyRenderResult(diff, options) != null) return diff;
|
|
463
|
+
if (this.renderCache == null) return diff;
|
|
464
|
+
if (areDiffTargetsEqual(this.renderCache.diff, diff)) return this.renderCache.diff;
|
|
465
|
+
const forcePlainText = !(diff.additionLines.length > 0 || diff.deletionLines.length > 0) || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
466
|
+
return this.canRenderDiff(diff, options, forcePlainText) ? diff : this.renderCache.diff;
|
|
467
|
+
}
|
|
468
|
+
canRenderDiff(diff, options, forcePlainText) {
|
|
469
|
+
const { renderCache } = this;
|
|
470
|
+
if (renderCache == null || areDiffTargetsEqual(renderCache.diff, diff)) return true;
|
|
471
|
+
if (forcePlainText) return renderCache.result == null && renderCache.hydrated !== true || this.workerManager?.isWorkingPool() === true || this.highlighter != null && areThemesAttached(options.theme);
|
|
472
|
+
if (renderCache.result == null && renderCache.hydrated !== true) return true;
|
|
473
|
+
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) return !renderCache.highlighted;
|
|
474
|
+
return this.highlighter != null && areThemesAttached(options.theme);
|
|
475
|
+
}
|
|
476
|
+
renderDiff(diff = this.diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
477
|
+
this.diff = diff;
|
|
478
|
+
if (diff == null) {
|
|
479
|
+
this.pendingHighlightResult = void 0;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
415
482
|
const { expandUnchanged, collapsedContextThreshold } = this.getOptionsWithDefaults();
|
|
416
483
|
let { options, forceHighlight } = this.getRenderOptions(diff);
|
|
417
|
-
const
|
|
418
|
-
|
|
484
|
+
const readyResult = this.getReadyRenderResult(diff, options);
|
|
485
|
+
this.pendingHighlightResult = void 0;
|
|
486
|
+
if (readyResult != null) {
|
|
419
487
|
this.renderCache = {
|
|
488
|
+
...readyResult,
|
|
420
489
|
diff,
|
|
421
|
-
|
|
422
|
-
renderRange: void 0,
|
|
423
|
-
...cache
|
|
490
|
+
renderRange: void 0
|
|
424
491
|
};
|
|
425
492
|
forceHighlight = false;
|
|
426
493
|
}
|
|
@@ -433,12 +500,12 @@ var DiffHunksRenderer = class {
|
|
|
433
500
|
};
|
|
434
501
|
const hasContent = diff.additionLines.length > 0 || diff.deletionLines.length > 0;
|
|
435
502
|
const forcePlainText = !hasContent || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
503
|
+
const canRenderDiff = this.canRenderDiff(diff, options, forcePlainText);
|
|
436
504
|
const newContent = !areDiffTargetsEqual(diff, this.renderCache.diff);
|
|
437
505
|
const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
|
|
438
506
|
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
|
|
439
|
-
const
|
|
440
|
-
if (
|
|
441
|
-
if (!highlightPending && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
|
|
507
|
+
const preserveHydratedContent = this.renderCache.result == null && this.renderCache.highlighted && !forcePlainText && !newContent && isDefaultRenderRange(renderRange);
|
|
508
|
+
if (canRenderDiff && !preserveHydratedContent && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
|
|
442
509
|
this.renderCache.diff = diff;
|
|
443
510
|
this.renderCache.options = options;
|
|
444
511
|
this.renderCache.highlighted = false;
|
|
@@ -448,10 +515,11 @@ var DiffHunksRenderer = class {
|
|
|
448
515
|
if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight)) this.workerManager.highlightDiffAST(this, diff);
|
|
449
516
|
} else {
|
|
450
517
|
this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);
|
|
518
|
+
this.highlighter ??= getHighlighterIfLoaded();
|
|
451
519
|
const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
|
|
452
520
|
const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLang);
|
|
453
521
|
const canHighlight = !forcePlainText && hasLangs;
|
|
454
|
-
if (this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
|
|
522
|
+
if (canRenderDiff && this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
|
|
455
523
|
const { result, options } = this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText || !hasLangs);
|
|
456
524
|
this.renderCache = {
|
|
457
525
|
diff,
|
|
@@ -462,13 +530,13 @@ var DiffHunksRenderer = class {
|
|
|
462
530
|
};
|
|
463
531
|
}
|
|
464
532
|
if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(diff).then(({ result, options }) => {
|
|
465
|
-
if (this.renderCache != null) this.renderCache.highlighted = false;
|
|
466
533
|
this.applyHighlightResult(diff, result, options, !forcePlainText);
|
|
467
534
|
});
|
|
468
535
|
}
|
|
469
536
|
return this.renderCache.result != null ? this.processDiffResult(this.renderCache.diff, renderRange, this.renderCache.result) : void 0;
|
|
470
537
|
}
|
|
471
538
|
async asyncRender(diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
539
|
+
this.diff = diff;
|
|
472
540
|
const { result } = await this.asyncHighlight(diff);
|
|
473
541
|
return this.processDiffResult(diff, renderRange, result);
|
|
474
542
|
}
|
|
@@ -527,16 +595,16 @@ var DiffHunksRenderer = class {
|
|
|
527
595
|
this.applyHighlightResult(diff, result, options, highlighted);
|
|
528
596
|
}
|
|
529
597
|
applyHighlightResult(diff, result, options, highlighted = true) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
598
|
+
const { diff: currentDiff, renderCache } = this;
|
|
599
|
+
if (currentDiff == null || renderCache == null || !areDiffTargetsEqual(currentDiff, diff) || !areDiffRenderOptionsEqual(options, this.getRenderOptions(currentDiff).options)) return;
|
|
600
|
+
if (!(renderCache.result == null || !renderCache.highlighted || !areDiffRenderOptionsEqual(renderCache.options, options) || !areDiffTargetsEqual(renderCache.diff, currentDiff))) return;
|
|
601
|
+
this.pendingHighlightResult = {
|
|
602
|
+
diff: currentDiff,
|
|
534
603
|
options,
|
|
535
604
|
highlighted,
|
|
536
|
-
result
|
|
537
|
-
renderRange: void 0
|
|
605
|
+
result
|
|
538
606
|
};
|
|
539
|
-
|
|
607
|
+
this.onRenderUpdate?.();
|
|
540
608
|
}
|
|
541
609
|
getMatchingWorkerResultCache(diff, options) {
|
|
542
610
|
if (this.editSessionActive) return;
|
|
@@ -544,6 +612,17 @@ var DiffHunksRenderer = class {
|
|
|
544
612
|
if (cache == null || !areDiffRenderOptionsEqual(options, cache.options)) return;
|
|
545
613
|
return cache;
|
|
546
614
|
}
|
|
615
|
+
getReadyRenderResult(diff, options) {
|
|
616
|
+
const { pendingHighlightResult } = this;
|
|
617
|
+
if (pendingHighlightResult != null && areDiffTargetsEqual(pendingHighlightResult.diff, diff) && areDiffRenderOptionsEqual(pendingHighlightResult.options, options)) return pendingHighlightResult;
|
|
618
|
+
const workerCache = this.getMatchingWorkerResultCache(diff, options);
|
|
619
|
+
if (workerCache == null || this.hasHighlightedRenderCache(diff, options)) return;
|
|
620
|
+
return {
|
|
621
|
+
diff,
|
|
622
|
+
highlighted: true,
|
|
623
|
+
...workerCache
|
|
624
|
+
};
|
|
625
|
+
}
|
|
547
626
|
hasHighlightedRenderCache(diff, options) {
|
|
548
627
|
const { renderCache } = this;
|
|
549
628
|
return renderCache?.result != null && renderCache.highlighted && areDiffTargetsEqual(diff, renderCache.diff) && areDiffRenderOptionsEqual(options, renderCache.options);
|
|
@@ -557,7 +636,6 @@ var DiffHunksRenderer = class {
|
|
|
557
636
|
processDiffResult(fileDiff, renderRange, { code, themeStyles, baseThemeType }) {
|
|
558
637
|
const { diffStyle, disableFileHeader, expandUnchanged, expansionLineCount, collapsedContextThreshold, hunkSeparators } = this.getOptionsWithDefaults();
|
|
559
638
|
const isRenderCacheDirty = this.renderCache?.isDirty ?? false;
|
|
560
|
-
this.diff = fileDiff;
|
|
561
639
|
const unified = diffStyle === "unified";
|
|
562
640
|
const canHydrateContext = canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null);
|
|
563
641
|
const isExpandableDiff = !fileDiff.isPartial || canHydrateContext;
|
|
@@ -821,6 +899,7 @@ var DiffHunksRenderer = class {
|
|
|
821
899
|
unifiedContentAST = unified && hasContent ? unifiedContentAST : void 0;
|
|
822
900
|
const preNode = this.createPreElement(deletionsContentAST != null && additionsContentAST != null, totalLines);
|
|
823
901
|
return {
|
|
902
|
+
fileDiff,
|
|
824
903
|
unifiedGutterAST: unified && hasContent ? context.unifiedGutterAST.children : void 0,
|
|
825
904
|
unifiedContentAST,
|
|
826
905
|
deletionsGutterAST: shouldIncludeDeletions && hasContent ? context.deletionsGutterAST.children : void 0,
|
|
@@ -831,7 +910,7 @@ var DiffHunksRenderer = class {
|
|
|
831
910
|
preNode,
|
|
832
911
|
themeStyles,
|
|
833
912
|
baseThemeType,
|
|
834
|
-
headerElement: !disableFileHeader ? this.renderHeader(
|
|
913
|
+
headerElement: !disableFileHeader ? this.renderHeader(fileDiff) : void 0,
|
|
835
914
|
totalLines,
|
|
836
915
|
rowCount: context.rowCount,
|
|
837
916
|
bufferBefore: renderRange.bufferBefore,
|
|
@@ -907,8 +986,8 @@ var DiffHunksRenderer = class {
|
|
|
907
986
|
}
|
|
908
987
|
pushFileLevelAnnotations(fileDiff, diffStyle, renderRange, context) {
|
|
909
988
|
if (!shouldRenderFileAnnotations(renderRange)) return;
|
|
910
|
-
const deletionAnnotationNames = fileDiff.type !== "new" ? getAnnotationNames(getFileAnnotations(this.deletionAnnotations)) : [];
|
|
911
|
-
const additionAnnotationNames = fileDiff.type !== "deleted" ? getAnnotationNames(getFileAnnotations(this.additionAnnotations)) : [];
|
|
989
|
+
const deletionAnnotationNames = fileDiff.type !== "new" ? this.getAnnotationNames(getFileAnnotations(this.deletionAnnotations)) : [];
|
|
990
|
+
const additionAnnotationNames = fileDiff.type !== "deleted" ? this.getAnnotationNames(getFileAnnotations(this.additionAnnotations)) : [];
|
|
912
991
|
if (deletionAnnotationNames.length === 0 && additionAnnotationNames.length === 0) return;
|
|
913
992
|
const hunkIndex = -1;
|
|
914
993
|
const lineIndex = -1;
|
|
@@ -954,14 +1033,14 @@ var DiffHunksRenderer = class {
|
|
|
954
1033
|
lineIndex,
|
|
955
1034
|
annotations: []
|
|
956
1035
|
};
|
|
957
|
-
if (deletionLineNumber != null) for (const anno of this.deletionAnnotations[deletionLineNumber] ?? []) deletionSpan.annotations.push(
|
|
1036
|
+
if (deletionLineNumber != null) for (const anno of this.deletionAnnotations[deletionLineNumber] ?? []) deletionSpan.annotations.push(this.annotationSlotName(anno));
|
|
958
1037
|
const additionSpan = {
|
|
959
1038
|
type: "annotation",
|
|
960
1039
|
hunkIndex,
|
|
961
1040
|
lineIndex,
|
|
962
1041
|
annotations: []
|
|
963
1042
|
};
|
|
964
|
-
if (additionLineNumber != null) for (const anno of this.additionAnnotations[additionLineNumber] ?? []) (type === "unified" ? deletionSpan : additionSpan).annotations.push(
|
|
1043
|
+
if (additionLineNumber != null) for (const anno of this.additionAnnotations[additionLineNumber] ?? []) (type === "unified" ? deletionSpan : additionSpan).annotations.push(this.annotationSlotName(anno));
|
|
965
1044
|
if (type === "unified") {
|
|
966
1045
|
if (deletionSpan.annotations.length > 0) return deletionSpan;
|
|
967
1046
|
return;
|
|
@@ -972,6 +1051,9 @@ var DiffHunksRenderer = class {
|
|
|
972
1051
|
additionSpan
|
|
973
1052
|
};
|
|
974
1053
|
}
|
|
1054
|
+
getAnnotationNames(annotations) {
|
|
1055
|
+
return annotations?.map((annotation) => this.annotationSlotName(annotation)) ?? [];
|
|
1056
|
+
}
|
|
975
1057
|
renderHeader(diff) {
|
|
976
1058
|
const { headerRenderMode, stickyHeader } = this.getOptionsWithDefaults();
|
|
977
1059
|
return createFileHeaderElement({
|
|
@@ -981,9 +1063,6 @@ var DiffHunksRenderer = class {
|
|
|
981
1063
|
});
|
|
982
1064
|
}
|
|
983
1065
|
};
|
|
984
|
-
function getAnnotationNames(annotations) {
|
|
985
|
-
return annotations?.map((annotation) => getLineAnnotationName(annotation)) ?? [];
|
|
986
|
-
}
|
|
987
1066
|
const EN_PLURAL_RULES = new Intl.PluralRules("en-US");
|
|
988
1067
|
function getModifiedLinesString(lines) {
|
|
989
1068
|
return `${lines} unmodified line${EN_PLURAL_RULES.select(lines) === "one" ? "" : "s"}`;
|
|
@@ -1143,7 +1222,6 @@ function realignAdditionHastLines(previousLines, nextLines, hastLines, textDocum
|
|
|
1143
1222
|
for (let index = 0; index < prefix; index++) realigned[index] = hastLines[index];
|
|
1144
1223
|
for (let offset = 0; offset < suffix; offset++) realigned[nextContentLength - 1 - offset] = hastLines[previousContentLength - 1 - offset];
|
|
1145
1224
|
if (previousContentLength < previousLines.length && nextContentLength < nextLines.length) realigned[nextLines.length - 1] = hastLines[previousLines.length - 1];
|
|
1146
|
-
for (let index = previousLines.length; index < nextLines.length; index++) realigned[index] ??= hastLines[index];
|
|
1147
1225
|
for (let index = prefix; index < nextLines.length; index++) realigned[index] ??= createPlainAdditionLineElement(index, textDocument.getLineText(index));
|
|
1148
1226
|
return realigned;
|
|
1149
1227
|
}
|
|
@@ -1167,26 +1245,11 @@ function createPlainAdditionLineElement(lineIndex, lineText, unifiedLineIndex =
|
|
|
1167
1245
|
}]
|
|
1168
1246
|
};
|
|
1169
1247
|
}
|
|
1170
|
-
function getEditorDocumentLines(textDocument
|
|
1248
|
+
function getEditorDocumentLines(textDocument) {
|
|
1171
1249
|
const lines = [];
|
|
1172
|
-
|
|
1173
|
-
for (let line = 0; line < textDocument.lineCount; line++) {
|
|
1174
|
-
const lineText = textDocument.getLineText(line, true);
|
|
1175
|
-
lines.push(line < textDocument.lineCount - 1 && !hasLineBreakSuffix(lineText) ? lineText + fallbackLineBreak : lineText);
|
|
1176
|
-
}
|
|
1250
|
+
for (let line = 0; line < textDocument.lineCount; line++) lines.push(textDocument.getLineText(line, true));
|
|
1177
1251
|
return lines;
|
|
1178
1252
|
}
|
|
1179
|
-
function hasLineBreakSuffix(line) {
|
|
1180
|
-
return line.endsWith("\n") || line.endsWith("\r");
|
|
1181
|
-
}
|
|
1182
|
-
function getFallbackLineBreak(lines) {
|
|
1183
|
-
for (const line of lines) {
|
|
1184
|
-
if (line.endsWith("\r\n")) return "\r\n";
|
|
1185
|
-
if (line.endsWith("\n")) return "\n";
|
|
1186
|
-
if (line.endsWith("\r")) return "\r";
|
|
1187
|
-
}
|
|
1188
|
-
return "\n";
|
|
1189
|
-
}
|
|
1190
1253
|
function isDiffMassive(diff, tokenizeMaxLength) {
|
|
1191
1254
|
return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
|
|
1192
1255
|
}
|