@pierre/diffs 1.3.5 → 1.4.0
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 +113 -68
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +153 -58
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +75 -15
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +223 -62
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +97 -21
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +400 -100
- package/dist/components/FileDiff.js.map +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 +16 -7
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +140 -51
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +14 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +183 -93
- 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 +1196 -403
- 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.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +3 -2
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +33 -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.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +6 -3
- 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/index.d.ts +8 -6
- package/dist/index.js +9 -8
- 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 -108
- 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 +138 -64
- 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 +33 -4
- 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,8 +1,4 @@
|
|
|
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
2
|
import { getFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
|
|
7
3
|
import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
|
|
8
4
|
import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.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,53 @@ 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
|
-
if (diff != null
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (!wasAlreadyActive) this.pendingHighlightResult = void 0;
|
|
85
|
+
if (diff != null) this.diff = diff;
|
|
86
|
+
const currentDiff = diff ?? this.diffCache;
|
|
87
|
+
if (currentDiff != null && !currentDiff.isPartial && currentDiff.additionLines.length === 0) {
|
|
88
|
+
Object.assign(currentDiff, recomputeEmptyDocumentDiff(currentDiff, this.options.parseDiffOptions));
|
|
89
|
+
this.markEditSessionPass(currentDiff);
|
|
90
|
+
this.clearRenderCache();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (diff == null) return;
|
|
94
|
+
if (renderCache == null) return;
|
|
95
|
+
if (wasAlreadyActive && renderCache.diff === diff) return;
|
|
96
|
+
const { options } = this.getRenderOptions(diff);
|
|
97
|
+
const cacheBelongsToSession = renderCache.diff === diff;
|
|
98
|
+
const cacheBelongsToExternal = externalDiff != null && areDiffTargetsEqual(renderCache.diff, externalDiff);
|
|
99
|
+
const { result } = renderCache;
|
|
100
|
+
if (!renderCache.highlighted || result == null || !areDiffRenderOptionsEqual(renderCache.options, options) || !cacheBelongsToSession && !cacheBelongsToExternal) {
|
|
82
101
|
this.clearRenderCache();
|
|
102
|
+
return;
|
|
83
103
|
}
|
|
104
|
+
if (cacheBelongsToSession) return;
|
|
105
|
+
this.renderCache = {
|
|
106
|
+
diff,
|
|
107
|
+
options,
|
|
108
|
+
highlighted: true,
|
|
109
|
+
result: {
|
|
110
|
+
...result,
|
|
111
|
+
code: {
|
|
112
|
+
...result.code,
|
|
113
|
+
additionLines: [...result.code.additionLines]
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
renderRange: renderCache.renderRange
|
|
117
|
+
};
|
|
84
118
|
}
|
|
85
119
|
/** Leave edit-session mode. The exit recompute is the host's concern. */
|
|
86
120
|
endEditSession() {
|
|
87
121
|
this.editSessionActive = false;
|
|
122
|
+
this.pendingHighlightResult = void 0;
|
|
88
123
|
}
|
|
89
124
|
/**
|
|
90
125
|
* Ensures that the DOM is compatible with editor render updates
|
|
@@ -93,20 +128,17 @@ var DiffHunksRenderer = class {
|
|
|
93
128
|
return this.renderCache?.options.useTokenTransformer === true && this.renderCache.highlighted && this.renderCache.result != null;
|
|
94
129
|
}
|
|
95
130
|
/**
|
|
96
|
-
* Re-highlights the current diff in the background and
|
|
97
|
-
* result
|
|
98
|
-
* session
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* interim paint drops highlighting.
|
|
131
|
+
* Re-highlights the current diff in the background and stages the fresh
|
|
132
|
+
* result for the next render. Needed after an edit session's exit recompute:
|
|
133
|
+
* session passes plain-fill shifted lines in the cached result, and the
|
|
134
|
+
* recompute mutates the keyless session diff in place, so object identity
|
|
135
|
+
* alone would otherwise treat the stale highlight as current forever. The
|
|
136
|
+
* current result — content-correct, mostly highlighted — keeps rendering
|
|
137
|
+
* until the fresh one is promoted, so no interim paint drops highlighting.
|
|
104
138
|
*/
|
|
105
139
|
refreshHighlightedResult() {
|
|
106
|
-
const { renderCache } = this;
|
|
107
|
-
if (renderCache == null ||
|
|
108
|
-
const { diff } = renderCache;
|
|
109
|
-
const { workerManager } = this;
|
|
140
|
+
const { diff, renderCache, workerManager } = this;
|
|
141
|
+
if (diff == null || renderCache == null || !areDiffTargetsEqual(renderCache.diff, diff) || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength())) return Promise.resolve();
|
|
110
142
|
if (!this.editSessionActive && workerManager?.isWorkingPool() === true && diff.cacheKey != null) {
|
|
111
143
|
workerManager.evictDiffFromCache(diff.cacheKey);
|
|
112
144
|
return workerManager.primeDiffHighlightCache(diff).then(() => {
|
|
@@ -116,15 +148,15 @@ var DiffHunksRenderer = class {
|
|
|
116
148
|
return this.asyncHighlight(diff).then((fresh) => this.applyRefreshedResult(diff, fresh)).catch((error) => this.onHighlightError(error));
|
|
117
149
|
}
|
|
118
150
|
applyRefreshedResult(diff, fresh) {
|
|
119
|
-
|
|
120
|
-
|
|
151
|
+
const { diff: currentDiff, renderCache } = this;
|
|
152
|
+
if (fresh == null || currentDiff == null || renderCache == null || !areDiffTargetsEqual(currentDiff, diff) || !areDiffTargetsEqual(renderCache.diff, diff) || this.editSessionActive) return;
|
|
153
|
+
const { options } = this.getRenderOptions(currentDiff);
|
|
121
154
|
if (!areDiffRenderOptionsEqual(options, fresh.options)) return;
|
|
122
|
-
this.
|
|
123
|
-
diff,
|
|
155
|
+
this.pendingHighlightResult = {
|
|
156
|
+
diff: currentDiff,
|
|
124
157
|
options: fresh.options,
|
|
125
158
|
highlighted: true,
|
|
126
|
-
result: fresh.result
|
|
127
|
-
renderRange: void 0
|
|
159
|
+
result: fresh.result
|
|
128
160
|
};
|
|
129
161
|
this.onRenderUpdate?.();
|
|
130
162
|
}
|
|
@@ -132,9 +164,9 @@ var DiffHunksRenderer = class {
|
|
|
132
164
|
return this.renderCache?.diff ?? this.diff;
|
|
133
165
|
}
|
|
134
166
|
clearRenderCache() {
|
|
135
|
-
const renderCache = this.renderCache;
|
|
136
167
|
this.renderCache = void 0;
|
|
137
|
-
|
|
168
|
+
this.pendingHighlightResult = void 0;
|
|
169
|
+
this.pendingStructuralRows = void 0;
|
|
138
170
|
}
|
|
139
171
|
setOptions(options) {
|
|
140
172
|
this.options = options;
|
|
@@ -187,11 +219,14 @@ var DiffHunksRenderer = class {
|
|
|
187
219
|
* re-render instead of its cheap refresh path.
|
|
188
220
|
*/
|
|
189
221
|
updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
|
|
190
|
-
|
|
191
|
-
const {
|
|
222
|
+
this.pendingStructuralRows = void 0;
|
|
223
|
+
const { renderCache } = this;
|
|
224
|
+
if (renderCache == null) return false;
|
|
225
|
+
const { result, diff } = renderCache;
|
|
192
226
|
if (result == null) return false;
|
|
193
227
|
if (diff.isPartial) throw new Error("Could not update render cache for partial diff");
|
|
194
228
|
const hastLines = result.code.additionLines;
|
|
229
|
+
const pendingStructuralRows = this.pendingStructuralRows = lineCountChangeInFlight ? /* @__PURE__ */ new Map() : void 0;
|
|
195
230
|
const changedAdditionLines = [];
|
|
196
231
|
const previousAdditionLines = /* @__PURE__ */ new Map();
|
|
197
232
|
for (const [line, tokens] of dirtyLines) {
|
|
@@ -200,14 +235,14 @@ var DiffHunksRenderer = class {
|
|
|
200
235
|
const canSyncDiffLine = line < diff.additionLines.length;
|
|
201
236
|
const prevLine = canSyncDiffLine ? diff.additionLines[line] ?? "" : "";
|
|
202
237
|
const prevText = cleanLastNewline(prevLine);
|
|
203
|
-
if (canSyncDiffLine) {
|
|
238
|
+
if (pendingStructuralRows == null && canSyncDiffLine) {
|
|
204
239
|
diff.additionLines[line] = applyLineTextWithNewline(prevLine, lineText);
|
|
205
240
|
if (prevText !== lineText) {
|
|
206
241
|
changedAdditionLines.push(line);
|
|
207
242
|
previousAdditionLines.set(line, prevLine);
|
|
208
243
|
}
|
|
209
244
|
}
|
|
210
|
-
|
|
245
|
+
const row = {
|
|
211
246
|
type: "element",
|
|
212
247
|
tagName: "div",
|
|
213
248
|
properties: {
|
|
@@ -242,56 +277,64 @@ var DiffHunksRenderer = class {
|
|
|
242
277
|
};
|
|
243
278
|
})
|
|
244
279
|
};
|
|
280
|
+
if (pendingStructuralRows != null) pendingStructuralRows.set(line, row);
|
|
281
|
+
else hastLines[line] = row;
|
|
245
282
|
}
|
|
246
283
|
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));
|
|
284
|
+
if (changedAdditionLines.length > 0) if (this.editSessionActive) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
285
|
+
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
286
|
+
regionsChanged = true;
|
|
287
|
+
} else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
|
|
288
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
|
|
289
|
+
regionsChanged = true;
|
|
290
|
+
} else {
|
|
291
|
+
const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
|
|
292
|
+
this.applyExpansionRemap(change);
|
|
293
|
+
regionsChanged = change != null;
|
|
294
|
+
}
|
|
295
|
+
else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
262
296
|
result.baseThemeType = themeType;
|
|
263
|
-
|
|
297
|
+
renderCache.isDirty = true;
|
|
264
298
|
return regionsChanged;
|
|
265
299
|
}
|
|
266
300
|
applyExpansionRemap(change) {
|
|
267
301
|
if (change != null) this.expandedHunks = remapExpandedHunksForRegionChange(this.expandedHunks, change);
|
|
268
302
|
}
|
|
269
303
|
applyDocumentChange(textDocument) {
|
|
270
|
-
|
|
271
|
-
|
|
304
|
+
const { pendingStructuralRows, renderCache } = this;
|
|
305
|
+
this.pendingStructuralRows = void 0;
|
|
306
|
+
if (renderCache == null) return;
|
|
307
|
+
const { diff, result } = renderCache;
|
|
272
308
|
if (result == null) return;
|
|
273
309
|
if (diff.isPartial) throw new Error("Could not apply document change for partial diff");
|
|
274
310
|
const { additionLines: previousAdditionLines } = diff;
|
|
275
|
-
diff.additionLines = getEditorDocumentLines(textDocument
|
|
311
|
+
diff.additionLines = getEditorDocumentLines(textDocument);
|
|
276
312
|
result.code.additionLines = realignAdditionHastLines(previousAdditionLines, diff.additionLines, result.code.additionLines, textDocument);
|
|
277
313
|
if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
278
|
-
|
|
314
|
+
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
279
315
|
result.code.additionLines[0] = createPlainAdditionLineElement(0, textDocument.getLineText(0));
|
|
280
|
-
this.markEditSessionPass(diff);
|
|
281
316
|
} else if (this.editSessionActive) this.applySessionDocumentChange(diff);
|
|
282
317
|
else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
|
|
283
|
-
|
|
318
|
+
if (pendingStructuralRows != null) {
|
|
319
|
+
for (const [line, row] of pendingStructuralRows) if (line < result.code.additionLines.length) result.code.additionLines[line] = row;
|
|
320
|
+
}
|
|
321
|
+
renderCache.isDirty = true;
|
|
284
322
|
}
|
|
285
323
|
applySessionDocumentChange(diff) {
|
|
286
324
|
const { parseDiffOptions } = this.options;
|
|
287
325
|
const rawLines = diff.additionLines;
|
|
288
326
|
if (shouldTopAlignAdditionRecompute(diff, rawLines)) {
|
|
289
|
-
|
|
290
|
-
this.markEditSessionPass(diff);
|
|
327
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, rawLines, parseDiffOptions));
|
|
291
328
|
return;
|
|
292
329
|
}
|
|
293
330
|
this.applyExpansionRemap(rebuildSessionHunks(diff, parseDiffOptions));
|
|
294
331
|
}
|
|
332
|
+
applyRecomputePreservingSessionType(diff, update) {
|
|
333
|
+
const sessionType = this.editSessionActive ? diff.type : void 0;
|
|
334
|
+
Object.assign(diff, update);
|
|
335
|
+
if (sessionType != null) diff.type = sessionType;
|
|
336
|
+
this.markEditSessionPass(diff);
|
|
337
|
+
}
|
|
295
338
|
markEditSessionPass(diff) {
|
|
296
339
|
if (!this.editSessionActive) return;
|
|
297
340
|
diff.editSessionDirty = true;
|
|
@@ -354,6 +397,7 @@ var DiffHunksRenderer = class {
|
|
|
354
397
|
if (cache != null && !areDiffRenderOptionsEqual(options, cache.options)) cache = void 0;
|
|
355
398
|
this.renderCache ??= {
|
|
356
399
|
diff,
|
|
400
|
+
hydrated: true,
|
|
357
401
|
highlighted: !massiveDiff && !isDiffPlainText(diff),
|
|
358
402
|
options,
|
|
359
403
|
result: massiveDiff ? void 0 : cache?.result,
|
|
@@ -410,17 +454,42 @@ var DiffHunksRenderer = class {
|
|
|
410
454
|
forceHighlight: false
|
|
411
455
|
};
|
|
412
456
|
}
|
|
413
|
-
|
|
414
|
-
|
|
457
|
+
/**
|
|
458
|
+
* Returns the diff that the next synchronous render can commit without
|
|
459
|
+
* changing the renderer's current diff or render cache. Components use this
|
|
460
|
+
* to prepare state that must match the following DOM render.
|
|
461
|
+
*/
|
|
462
|
+
getDiffForNextRender(diff) {
|
|
463
|
+
const { options } = this.getRenderOptions(diff);
|
|
464
|
+
if (this.getReadyRenderResult(diff, options) != null) return diff;
|
|
465
|
+
if (this.renderCache == null) return diff;
|
|
466
|
+
if (areDiffTargetsEqual(this.renderCache.diff, diff)) return this.renderCache.diff;
|
|
467
|
+
const forcePlainText = !(diff.additionLines.length > 0 || diff.deletionLines.length > 0) || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
468
|
+
return this.canRenderDiff(diff, options, forcePlainText) ? diff : this.renderCache.diff;
|
|
469
|
+
}
|
|
470
|
+
canRenderDiff(diff, options, forcePlainText) {
|
|
471
|
+
const { renderCache } = this;
|
|
472
|
+
if (renderCache == null || areDiffTargetsEqual(renderCache.diff, diff)) return true;
|
|
473
|
+
if (forcePlainText) return renderCache.result == null && renderCache.hydrated !== true || this.workerManager?.isWorkingPool() === true || this.highlighter != null && areThemesAttached(options.theme);
|
|
474
|
+
if (renderCache.result == null && renderCache.hydrated !== true) return true;
|
|
475
|
+
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) return !renderCache.highlighted;
|
|
476
|
+
return this.highlighter != null && areThemesAttached(options.theme);
|
|
477
|
+
}
|
|
478
|
+
renderDiff(diff = this.diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
479
|
+
this.diff = diff;
|
|
480
|
+
if (diff == null) {
|
|
481
|
+
this.pendingHighlightResult = void 0;
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
415
484
|
const { expandUnchanged, collapsedContextThreshold } = this.getOptionsWithDefaults();
|
|
416
485
|
let { options, forceHighlight } = this.getRenderOptions(diff);
|
|
417
|
-
const
|
|
418
|
-
|
|
486
|
+
const readyResult = this.getReadyRenderResult(diff, options);
|
|
487
|
+
this.pendingHighlightResult = void 0;
|
|
488
|
+
if (readyResult != null) {
|
|
419
489
|
this.renderCache = {
|
|
490
|
+
...readyResult,
|
|
420
491
|
diff,
|
|
421
|
-
|
|
422
|
-
renderRange: void 0,
|
|
423
|
-
...cache
|
|
492
|
+
renderRange: void 0
|
|
424
493
|
};
|
|
425
494
|
forceHighlight = false;
|
|
426
495
|
}
|
|
@@ -433,12 +502,12 @@ var DiffHunksRenderer = class {
|
|
|
433
502
|
};
|
|
434
503
|
const hasContent = diff.additionLines.length > 0 || diff.deletionLines.length > 0;
|
|
435
504
|
const forcePlainText = !hasContent || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
505
|
+
const canRenderDiff = this.canRenderDiff(diff, options, forcePlainText);
|
|
436
506
|
const newContent = !areDiffTargetsEqual(diff, this.renderCache.diff);
|
|
437
507
|
const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
|
|
438
508
|
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
|
|
439
|
-
const
|
|
440
|
-
if (
|
|
441
|
-
if (!highlightPending && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
|
|
509
|
+
const preserveHydratedContent = this.renderCache.result == null && this.renderCache.highlighted && !forcePlainText && !newContent && isDefaultRenderRange(renderRange);
|
|
510
|
+
if (canRenderDiff && !preserveHydratedContent && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
|
|
442
511
|
this.renderCache.diff = diff;
|
|
443
512
|
this.renderCache.options = options;
|
|
444
513
|
this.renderCache.highlighted = false;
|
|
@@ -451,7 +520,7 @@ var DiffHunksRenderer = class {
|
|
|
451
520
|
const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
|
|
452
521
|
const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLang);
|
|
453
522
|
const canHighlight = !forcePlainText && hasLangs;
|
|
454
|
-
if (this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
|
|
523
|
+
if (canRenderDiff && this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
|
|
455
524
|
const { result, options } = this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText || !hasLangs);
|
|
456
525
|
this.renderCache = {
|
|
457
526
|
diff,
|
|
@@ -462,13 +531,13 @@ var DiffHunksRenderer = class {
|
|
|
462
531
|
};
|
|
463
532
|
}
|
|
464
533
|
if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(diff).then(({ result, options }) => {
|
|
465
|
-
if (this.renderCache != null) this.renderCache.highlighted = false;
|
|
466
534
|
this.applyHighlightResult(diff, result, options, !forcePlainText);
|
|
467
535
|
});
|
|
468
536
|
}
|
|
469
537
|
return this.renderCache.result != null ? this.processDiffResult(this.renderCache.diff, renderRange, this.renderCache.result) : void 0;
|
|
470
538
|
}
|
|
471
539
|
async asyncRender(diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
540
|
+
this.diff = diff;
|
|
472
541
|
const { result } = await this.asyncHighlight(diff);
|
|
473
542
|
return this.processDiffResult(diff, renderRange, result);
|
|
474
543
|
}
|
|
@@ -527,16 +596,16 @@ var DiffHunksRenderer = class {
|
|
|
527
596
|
this.applyHighlightResult(diff, result, options, highlighted);
|
|
528
597
|
}
|
|
529
598
|
applyHighlightResult(diff, result, options, highlighted = true) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
599
|
+
const { diff: currentDiff, renderCache } = this;
|
|
600
|
+
if (currentDiff == null || renderCache == null || !areDiffTargetsEqual(currentDiff, diff) || !areDiffRenderOptionsEqual(options, this.getRenderOptions(currentDiff).options)) return;
|
|
601
|
+
if (!(renderCache.result == null || !renderCache.highlighted || !areDiffRenderOptionsEqual(renderCache.options, options) || !areDiffTargetsEqual(renderCache.diff, currentDiff))) return;
|
|
602
|
+
this.pendingHighlightResult = {
|
|
603
|
+
diff: currentDiff,
|
|
534
604
|
options,
|
|
535
605
|
highlighted,
|
|
536
|
-
result
|
|
537
|
-
renderRange: void 0
|
|
606
|
+
result
|
|
538
607
|
};
|
|
539
|
-
|
|
608
|
+
this.onRenderUpdate?.();
|
|
540
609
|
}
|
|
541
610
|
getMatchingWorkerResultCache(diff, options) {
|
|
542
611
|
if (this.editSessionActive) return;
|
|
@@ -544,6 +613,17 @@ var DiffHunksRenderer = class {
|
|
|
544
613
|
if (cache == null || !areDiffRenderOptionsEqual(options, cache.options)) return;
|
|
545
614
|
return cache;
|
|
546
615
|
}
|
|
616
|
+
getReadyRenderResult(diff, options) {
|
|
617
|
+
const { pendingHighlightResult } = this;
|
|
618
|
+
if (pendingHighlightResult != null && areDiffTargetsEqual(pendingHighlightResult.diff, diff) && areDiffRenderOptionsEqual(pendingHighlightResult.options, options)) return pendingHighlightResult;
|
|
619
|
+
const workerCache = this.getMatchingWorkerResultCache(diff, options);
|
|
620
|
+
if (workerCache == null || this.hasHighlightedRenderCache(diff, options)) return;
|
|
621
|
+
return {
|
|
622
|
+
diff,
|
|
623
|
+
highlighted: true,
|
|
624
|
+
...workerCache
|
|
625
|
+
};
|
|
626
|
+
}
|
|
547
627
|
hasHighlightedRenderCache(diff, options) {
|
|
548
628
|
const { renderCache } = this;
|
|
549
629
|
return renderCache?.result != null && renderCache.highlighted && areDiffTargetsEqual(diff, renderCache.diff) && areDiffRenderOptionsEqual(options, renderCache.options);
|
|
@@ -557,7 +637,6 @@ var DiffHunksRenderer = class {
|
|
|
557
637
|
processDiffResult(fileDiff, renderRange, { code, themeStyles, baseThemeType }) {
|
|
558
638
|
const { diffStyle, disableFileHeader, expandUnchanged, expansionLineCount, collapsedContextThreshold, hunkSeparators } = this.getOptionsWithDefaults();
|
|
559
639
|
const isRenderCacheDirty = this.renderCache?.isDirty ?? false;
|
|
560
|
-
this.diff = fileDiff;
|
|
561
640
|
const unified = diffStyle === "unified";
|
|
562
641
|
const canHydrateContext = canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null);
|
|
563
642
|
const isExpandableDiff = !fileDiff.isPartial || canHydrateContext;
|
|
@@ -821,6 +900,7 @@ var DiffHunksRenderer = class {
|
|
|
821
900
|
unifiedContentAST = unified && hasContent ? unifiedContentAST : void 0;
|
|
822
901
|
const preNode = this.createPreElement(deletionsContentAST != null && additionsContentAST != null, totalLines);
|
|
823
902
|
return {
|
|
903
|
+
fileDiff,
|
|
824
904
|
unifiedGutterAST: unified && hasContent ? context.unifiedGutterAST.children : void 0,
|
|
825
905
|
unifiedContentAST,
|
|
826
906
|
deletionsGutterAST: shouldIncludeDeletions && hasContent ? context.deletionsGutterAST.children : void 0,
|
|
@@ -831,7 +911,7 @@ var DiffHunksRenderer = class {
|
|
|
831
911
|
preNode,
|
|
832
912
|
themeStyles,
|
|
833
913
|
baseThemeType,
|
|
834
|
-
headerElement: !disableFileHeader ? this.renderHeader(
|
|
914
|
+
headerElement: !disableFileHeader ? this.renderHeader(fileDiff) : void 0,
|
|
835
915
|
totalLines,
|
|
836
916
|
rowCount: context.rowCount,
|
|
837
917
|
bufferBefore: renderRange.bufferBefore,
|
|
@@ -907,8 +987,8 @@ var DiffHunksRenderer = class {
|
|
|
907
987
|
}
|
|
908
988
|
pushFileLevelAnnotations(fileDiff, diffStyle, renderRange, context) {
|
|
909
989
|
if (!shouldRenderFileAnnotations(renderRange)) return;
|
|
910
|
-
const deletionAnnotationNames = fileDiff.type !== "new" ? getAnnotationNames(getFileAnnotations(this.deletionAnnotations)) : [];
|
|
911
|
-
const additionAnnotationNames = fileDiff.type !== "deleted" ? getAnnotationNames(getFileAnnotations(this.additionAnnotations)) : [];
|
|
990
|
+
const deletionAnnotationNames = fileDiff.type !== "new" ? this.getAnnotationNames(getFileAnnotations(this.deletionAnnotations)) : [];
|
|
991
|
+
const additionAnnotationNames = fileDiff.type !== "deleted" ? this.getAnnotationNames(getFileAnnotations(this.additionAnnotations)) : [];
|
|
912
992
|
if (deletionAnnotationNames.length === 0 && additionAnnotationNames.length === 0) return;
|
|
913
993
|
const hunkIndex = -1;
|
|
914
994
|
const lineIndex = -1;
|
|
@@ -954,14 +1034,14 @@ var DiffHunksRenderer = class {
|
|
|
954
1034
|
lineIndex,
|
|
955
1035
|
annotations: []
|
|
956
1036
|
};
|
|
957
|
-
if (deletionLineNumber != null) for (const anno of this.deletionAnnotations[deletionLineNumber] ?? []) deletionSpan.annotations.push(
|
|
1037
|
+
if (deletionLineNumber != null) for (const anno of this.deletionAnnotations[deletionLineNumber] ?? []) deletionSpan.annotations.push(this.annotationSlotName(anno));
|
|
958
1038
|
const additionSpan = {
|
|
959
1039
|
type: "annotation",
|
|
960
1040
|
hunkIndex,
|
|
961
1041
|
lineIndex,
|
|
962
1042
|
annotations: []
|
|
963
1043
|
};
|
|
964
|
-
if (additionLineNumber != null) for (const anno of this.additionAnnotations[additionLineNumber] ?? []) (type === "unified" ? deletionSpan : additionSpan).annotations.push(
|
|
1044
|
+
if (additionLineNumber != null) for (const anno of this.additionAnnotations[additionLineNumber] ?? []) (type === "unified" ? deletionSpan : additionSpan).annotations.push(this.annotationSlotName(anno));
|
|
965
1045
|
if (type === "unified") {
|
|
966
1046
|
if (deletionSpan.annotations.length > 0) return deletionSpan;
|
|
967
1047
|
return;
|
|
@@ -972,6 +1052,9 @@ var DiffHunksRenderer = class {
|
|
|
972
1052
|
additionSpan
|
|
973
1053
|
};
|
|
974
1054
|
}
|
|
1055
|
+
getAnnotationNames(annotations) {
|
|
1056
|
+
return annotations?.map((annotation) => this.annotationSlotName(annotation)) ?? [];
|
|
1057
|
+
}
|
|
975
1058
|
renderHeader(diff) {
|
|
976
1059
|
const { headerRenderMode, stickyHeader } = this.getOptionsWithDefaults();
|
|
977
1060
|
return createFileHeaderElement({
|
|
@@ -981,9 +1064,6 @@ var DiffHunksRenderer = class {
|
|
|
981
1064
|
});
|
|
982
1065
|
}
|
|
983
1066
|
};
|
|
984
|
-
function getAnnotationNames(annotations) {
|
|
985
|
-
return annotations?.map((annotation) => getLineAnnotationName(annotation)) ?? [];
|
|
986
|
-
}
|
|
987
1067
|
const EN_PLURAL_RULES = new Intl.PluralRules("en-US");
|
|
988
1068
|
function getModifiedLinesString(lines) {
|
|
989
1069
|
return `${lines} unmodified line${EN_PLURAL_RULES.select(lines) === "one" ? "" : "s"}`;
|
|
@@ -1143,7 +1223,6 @@ function realignAdditionHastLines(previousLines, nextLines, hastLines, textDocum
|
|
|
1143
1223
|
for (let index = 0; index < prefix; index++) realigned[index] = hastLines[index];
|
|
1144
1224
|
for (let offset = 0; offset < suffix; offset++) realigned[nextContentLength - 1 - offset] = hastLines[previousContentLength - 1 - offset];
|
|
1145
1225
|
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
1226
|
for (let index = prefix; index < nextLines.length; index++) realigned[index] ??= createPlainAdditionLineElement(index, textDocument.getLineText(index));
|
|
1148
1227
|
return realigned;
|
|
1149
1228
|
}
|
|
@@ -1167,26 +1246,11 @@ function createPlainAdditionLineElement(lineIndex, lineText, unifiedLineIndex =
|
|
|
1167
1246
|
}]
|
|
1168
1247
|
};
|
|
1169
1248
|
}
|
|
1170
|
-
function getEditorDocumentLines(textDocument
|
|
1249
|
+
function getEditorDocumentLines(textDocument) {
|
|
1171
1250
|
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
|
-
}
|
|
1251
|
+
for (let line = 0; line < textDocument.lineCount; line++) lines.push(textDocument.getLineText(line, true));
|
|
1177
1252
|
return lines;
|
|
1178
1253
|
}
|
|
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
1254
|
function isDiffMassive(diff, tokenizeMaxLength) {
|
|
1191
1255
|
return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
|
|
1192
1256
|
}
|