@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,16 +1,15 @@
|
|
|
1
1
|
import { CUSTOM_HEADER_SLOT_ID, DEFAULT_THEMES, EMPTY_RENDER_RANGE, HEADER_FILENAME_SUFFIX_SLOT_ID, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID } from "../constants.js";
|
|
2
|
+
import { getThemes } from "../utils/getThemes.js";
|
|
3
|
+
import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
|
|
2
4
|
import { dequeueRender, queueRender } from "../managers/UniversalRenderingManager.js";
|
|
3
5
|
import { areThemesEqual } from "../utils/areThemesEqual.js";
|
|
4
|
-
import { getHunkSideStartBoundary } from "../utils/getHunkSideBoundaries.js";
|
|
5
|
-
import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
|
|
6
|
-
import { getExpandedRegion, getHunkAdditionLineRange, getNearestRenderableAdditionLine, getTrailingExpandedRegion, isAdditionLineRenderable } from "../utils/virtualDiffLayout.js";
|
|
7
|
-
import { captureExpansionAnchors, finishEditSessionForDiff, rebuildExpansionFromAnchors } from "../utils/editSessionHunks.js";
|
|
8
6
|
import { isStyleNode } from "../utils/isStyleNode.js";
|
|
9
|
-
import { areFilesEqual } from "../utils/areFilesEqual.js";
|
|
10
7
|
import { InteractionManager, pluckInteractionOptions } from "../managers/InteractionManager.js";
|
|
11
8
|
import { ResizeManager } from "../managers/ResizeManager.js";
|
|
12
9
|
import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
|
|
10
|
+
import { getFiletypeFromFileName } from "../utils/getFiletypeFromFileName.js";
|
|
13
11
|
import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
12
|
+
import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
|
|
14
13
|
import { SVGSpriteSheet } from "../sprite.js";
|
|
15
14
|
import { arePrePropertiesEqual } from "../utils/arePrePropertiesEqual.js";
|
|
16
15
|
import { createAnnotationWrapperNode } from "../utils/createAnnotationWrapperNode.js";
|
|
@@ -18,6 +17,7 @@ import { createGutterUtilityContentNode } from "../utils/createGutterUtilityCont
|
|
|
18
17
|
import { createUnsafeCSSStyleNode } from "../utils/createUnsafeCSSStyleNode.js";
|
|
19
18
|
import { getMeasuredScrollbarGutter } from "../utils/scrollbarGutter.js";
|
|
20
19
|
import { patchScrollbarGutterSize, wrapThemeCSS, wrapUnsafeCSS } from "../utils/cssWrappers.js";
|
|
20
|
+
import { adoptEditSessionAnnotations, resolveEditSessionSlotName, writeEditSessionAnnotations } from "../utils/editSessionAnnotations.js";
|
|
21
21
|
import { getOrCreateCodeNode } from "../utils/getOrCreateCodeNode.js";
|
|
22
22
|
import { guardWebKitScrollDuringRebuild } from "../utils/guardWebKitScrollDuringRebuild.js";
|
|
23
23
|
import { upsertHostThemeStyle } from "../utils/hostTheme.js";
|
|
@@ -25,12 +25,20 @@ import { isSafari } from "../utils/platform.js";
|
|
|
25
25
|
import { prerenderHTMLIfNecessary } from "../utils/prerenderHTMLIfNecessary.js";
|
|
26
26
|
import { setPreNodeProperties } from "../utils/setWrapperNodeProps.js";
|
|
27
27
|
import "./web-components.js";
|
|
28
|
+
import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
|
|
29
|
+
import { areFilesEqual } from "../utils/areFilesEqual.js";
|
|
28
30
|
import { awaitWithTimeout } from "../utils/awaitWithTimeout.js";
|
|
31
|
+
import { getHunkSideStartBoundary } from "../utils/getHunkSideBoundaries.js";
|
|
32
|
+
import { getExpandedRegion, getHunkAdditionLineRange, getNearestRenderableAdditionLine, getTrailingExpandedRegion, isAdditionLineRenderable } from "../utils/virtualDiffLayout.js";
|
|
29
33
|
import { getDiffFileInput } from "../utils/getDiffFileInput.js";
|
|
34
|
+
import { cloneFileDiffMetadata, cloneHunks } from "../utils/cloneFileDiffMetadata.js";
|
|
35
|
+
import { splitFileContents } from "../utils/splitFileContents.js";
|
|
30
36
|
import { hydratePartialDiff } from "../utils/hydratePartialDiff.js";
|
|
31
37
|
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
38
|
+
import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
|
|
32
39
|
import { ScrollSyncManager } from "../managers/ScrollSyncManager.js";
|
|
33
|
-
import {
|
|
40
|
+
import { recomputeDiffRenderLineCounts } from "../utils/updateDiffHunks.js";
|
|
41
|
+
import { captureExpansionAnchors, finishEditSessionForDiff, rebuildExpansionFromAnchors } from "../utils/editSessionHunks.js";
|
|
34
42
|
import { isDiffPlainText } from "../utils/isDiffPlainText.js";
|
|
35
43
|
import { DiffHunksRenderer } from "../renderers/DiffHunksRenderer.js";
|
|
36
44
|
import { areDiffLineAnnotationsEqual } from "../utils/areDiffLineAnnotationsEqual.js";
|
|
@@ -41,6 +49,28 @@ import { toHtml } from "hast-util-to-html";
|
|
|
41
49
|
function canHydrateDiff(fileDiff) {
|
|
42
50
|
return fileDiff.isPartial && (fileDiff.type === "change" || fileDiff.type === "rename-changed" || fileDiff.type === "rename-pure");
|
|
43
51
|
}
|
|
52
|
+
function createEditSessionDiff(fileDiff) {
|
|
53
|
+
const editSessionDiff = { ...fileDiff };
|
|
54
|
+
delete editSessionDiff.cacheKey;
|
|
55
|
+
return editSessionDiff;
|
|
56
|
+
}
|
|
57
|
+
function shouldResetUndoState(prevDiff, nextDiff) {
|
|
58
|
+
if (prevDiff.isPartial || nextDiff.isPartial) throw new Error("FileDiff.shouldResetEditorForExternalDiff: diffs must be fully hydrated");
|
|
59
|
+
const prevLanguage = prevDiff.lang ?? getFiletypeFromFileName(prevDiff.name);
|
|
60
|
+
const nextLanguage = nextDiff.lang ?? getFiletypeFromFileName(nextDiff.name);
|
|
61
|
+
const prevHasOldFile = prevDiff.type !== "new";
|
|
62
|
+
const nextHasOldFile = nextDiff.type !== "new";
|
|
63
|
+
if (prevDiff.name !== nextDiff.name || prevLanguage !== nextLanguage || prevHasOldFile !== nextHasOldFile || prevDiff.deletionLines.length !== nextDiff.deletionLines.length) return true;
|
|
64
|
+
return prevDiff.deletionLines.some((line, index) => line !== nextDiff.deletionLines[index]);
|
|
65
|
+
}
|
|
66
|
+
function areLinesEqual(first, second) {
|
|
67
|
+
return first.length === second.length && first.every((line, index) => line === second[index]);
|
|
68
|
+
}
|
|
69
|
+
function canRestoreDiffSession(snapshot, externalDiff) {
|
|
70
|
+
const { oldFile } = snapshot;
|
|
71
|
+
if (oldFile == null) return externalDiff.type === "new";
|
|
72
|
+
return externalDiff.type !== "new" && oldFile.name === (externalDiff.prevName ?? externalDiff.name) && areLinesEqual(oldFile.lines, externalDiff.deletionLines);
|
|
73
|
+
}
|
|
44
74
|
let instanceId = -1;
|
|
45
75
|
var FileDiff = class {
|
|
46
76
|
options;
|
|
@@ -81,11 +111,16 @@ var FileDiff = class {
|
|
|
81
111
|
deletionFile;
|
|
82
112
|
additionFile;
|
|
83
113
|
fileDiff;
|
|
114
|
+
editSession;
|
|
115
|
+
renderedDiff;
|
|
84
116
|
renderRange;
|
|
85
117
|
pendingFiles;
|
|
86
118
|
appliedPreAttributes;
|
|
87
|
-
|
|
88
|
-
|
|
119
|
+
headerCache = {
|
|
120
|
+
lastRenderedHTML: void 0,
|
|
121
|
+
html: void 0,
|
|
122
|
+
fileDiff: void 0
|
|
123
|
+
};
|
|
89
124
|
lastRowCount;
|
|
90
125
|
mounted = false;
|
|
91
126
|
enabled = true;
|
|
@@ -108,14 +143,22 @@ var FileDiff = class {
|
|
|
108
143
|
handleHighlightRender = () => {
|
|
109
144
|
this.rerender();
|
|
110
145
|
};
|
|
146
|
+
getTheme() {
|
|
147
|
+
return this.workerManager?.getDiffRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
|
|
148
|
+
}
|
|
111
149
|
getHunksRendererOptions(options) {
|
|
112
150
|
return getDiffHunksRendererOptions(options);
|
|
113
151
|
}
|
|
114
152
|
createHunksRenderer(options) {
|
|
115
|
-
return new DiffHunksRenderer(this.getHunksRendererOptions(options), this.handleHighlightRender, this.workerManager);
|
|
153
|
+
return new DiffHunksRenderer(this.getHunksRendererOptions(options), this.getAnnotationSlotName, this.handleHighlightRender, this.workerManager);
|
|
116
154
|
}
|
|
117
155
|
getLineIndex = (lineNumber, side = "additions") => {
|
|
118
|
-
|
|
156
|
+
return this.getLineIndexForDiff(this.getDiffForLineIndex(), lineNumber, side);
|
|
157
|
+
};
|
|
158
|
+
getDiffForLineIndex() {
|
|
159
|
+
return this.getRenderedDiff();
|
|
160
|
+
}
|
|
161
|
+
getLineIndexForDiff(fileDiff, lineNumber, side) {
|
|
119
162
|
if (fileDiff == null) return;
|
|
120
163
|
const lastHunk = fileDiff.hunks.at(-1);
|
|
121
164
|
let targetUnifiedIndex;
|
|
@@ -168,11 +211,11 @@ var FileDiff = class {
|
|
|
168
211
|
}
|
|
169
212
|
if (targetUnifiedIndex == null || targetSplitIndex == null) return;
|
|
170
213
|
return [targetUnifiedIndex, targetSplitIndex];
|
|
171
|
-
}
|
|
214
|
+
}
|
|
172
215
|
setOptions(options) {
|
|
173
216
|
if (options == null) return;
|
|
174
217
|
this.options = options;
|
|
175
|
-
this.
|
|
218
|
+
this.clearReusableHeader();
|
|
176
219
|
this.hunksRenderer.setOptions(this.getHunksRendererOptions(options));
|
|
177
220
|
this.syncInteractionOptions();
|
|
178
221
|
}
|
|
@@ -198,13 +241,39 @@ var FileDiff = class {
|
|
|
198
241
|
return true;
|
|
199
242
|
}
|
|
200
243
|
hasThemeChanged() {
|
|
201
|
-
return this.appliedThemeCSS != null && !areThemesEqual(this.appliedThemeCSS.theme, this.
|
|
244
|
+
return this.appliedThemeCSS != null && !areThemesEqual(this.appliedThemeCSS.theme, this.getTheme());
|
|
202
245
|
}
|
|
203
246
|
getHoveredLine = () => {
|
|
204
247
|
return this.interactionManager.getHoveredLine();
|
|
205
248
|
};
|
|
249
|
+
getAnnotationSlotName = (annotation) => {
|
|
250
|
+
return resolveEditSessionSlotName(this.editSession?.annotations, annotation, getLineAnnotationName);
|
|
251
|
+
};
|
|
252
|
+
getLatestAnnotations() {
|
|
253
|
+
return this.editSession?.annotations?.current ?? this.lineAnnotations;
|
|
254
|
+
}
|
|
255
|
+
isNewAnnotations(lineAnnotations) {
|
|
256
|
+
const session = this.editSession?.annotations;
|
|
257
|
+
if (lineAnnotations === this.lineAnnotations) return false;
|
|
258
|
+
return session == null || lineAnnotations !== session.provided && lineAnnotations !== session.current;
|
|
259
|
+
}
|
|
206
260
|
setLineAnnotations(lineAnnotations) {
|
|
261
|
+
const sessionAnnotations = this.editSession?.annotations;
|
|
262
|
+
if (sessionAnnotations == null) {
|
|
263
|
+
this.lineAnnotations = lineAnnotations;
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (!this.isNewAnnotations(lineAnnotations)) return;
|
|
207
267
|
this.lineAnnotations = lineAnnotations;
|
|
268
|
+
writeEditSessionAnnotations(sessionAnnotations, lineAnnotations, getLineAnnotationName);
|
|
269
|
+
}
|
|
270
|
+
syncEditSessionAnnotationsFromEditor(lineAnnotations) {
|
|
271
|
+
const session = this.editSession?.annotations;
|
|
272
|
+
if (session == null || lineAnnotations === session.current) return false;
|
|
273
|
+
session.current = lineAnnotations;
|
|
274
|
+
this.hunksRenderer.setLineAnnotations(lineAnnotations);
|
|
275
|
+
this.renderAnnotations();
|
|
276
|
+
return true;
|
|
208
277
|
}
|
|
209
278
|
canPartiallyRender(forceRender, annotationsChanged, didContentChange) {
|
|
210
279
|
if (forceRender || annotationsChanged || didContentChange || typeof this.options.hunkSeparators === "function") return false;
|
|
@@ -246,7 +315,7 @@ var FileDiff = class {
|
|
|
246
315
|
}
|
|
247
316
|
shouldApplyColumnVariables(overflow) {
|
|
248
317
|
if (typeof this.options.hunkSeparators === "function") return true;
|
|
249
|
-
return overflow === "scroll" && (this.
|
|
318
|
+
return overflow === "scroll" && (this.getLatestAnnotations().length > 0 || this.pre?.hasAttribute("data-has-merge-conflict") === true);
|
|
250
319
|
}
|
|
251
320
|
getCodeScrollLeft() {
|
|
252
321
|
return Math.max(this.codeUnified?.scrollLeft ?? 0, this.codeDeletions?.scrollLeft ?? 0, this.codeAdditions?.scrollLeft ?? 0);
|
|
@@ -263,17 +332,18 @@ var FileDiff = class {
|
|
|
263
332
|
};
|
|
264
333
|
}
|
|
265
334
|
cleanUp(recycle = false) {
|
|
335
|
+
const { editor } = this;
|
|
266
336
|
dequeueRender(this.handleEditSessionRender);
|
|
267
337
|
this.emitPostRender(true);
|
|
268
|
-
|
|
269
|
-
this.editor = void 0;
|
|
338
|
+
editor?.cleanUp(recycle ? "recycle" : "discard");
|
|
339
|
+
if (!recycle) this.editor = void 0;
|
|
270
340
|
this.resizeManager.cleanUp();
|
|
271
341
|
this.interactionManager.cleanUp();
|
|
272
342
|
this.scrollSyncManager.cleanUp();
|
|
273
343
|
this.managersDirty = false;
|
|
274
344
|
this.workerManager?.unsubscribeToThemeChanges(this);
|
|
275
345
|
this.renderRange = void 0;
|
|
276
|
-
this.pendingFiles = void 0;
|
|
346
|
+
if (!recycle) this.pendingFiles = void 0;
|
|
277
347
|
if (!this.isContainerManaged) this.fileContainer?.remove();
|
|
278
348
|
this.fileContainer = void 0;
|
|
279
349
|
this.mounted = false;
|
|
@@ -296,8 +366,8 @@ var FileDiff = class {
|
|
|
296
366
|
this.headerCustom = void 0;
|
|
297
367
|
this.placeHolder?.remove();
|
|
298
368
|
this.placeHolder = void 0;
|
|
299
|
-
this.
|
|
300
|
-
if (!recycle) this.
|
|
369
|
+
this.headerCache.lastRenderedHTML = void 0;
|
|
370
|
+
if (!recycle) this.clearReusableHeader();
|
|
301
371
|
this.errorWrapper?.remove();
|
|
302
372
|
this.errorWrapper = void 0;
|
|
303
373
|
this.spriteSVG = void 0;
|
|
@@ -312,6 +382,8 @@ var FileDiff = class {
|
|
|
312
382
|
this.hunksRenderer.cleanUp();
|
|
313
383
|
this.workerManager = void 0;
|
|
314
384
|
this.fileDiff = void 0;
|
|
385
|
+
this.editSession = void 0;
|
|
386
|
+
this.renderedDiff = void 0;
|
|
315
387
|
this.deletionFile = void 0;
|
|
316
388
|
this.additionFile = void 0;
|
|
317
389
|
}
|
|
@@ -335,7 +407,8 @@ var FileDiff = class {
|
|
|
335
407
|
const oldFile = fileInput?.oldFile;
|
|
336
408
|
const newFile = fileInput?.newFile;
|
|
337
409
|
this.hydrateElements(fileContainer, prerenderedHTML);
|
|
338
|
-
|
|
410
|
+
const forceEditorRender = this.editor != null;
|
|
411
|
+
if (forceEditorRender || shouldRenderCode(this.pre, hasDiffContent({
|
|
339
412
|
fileDiff,
|
|
340
413
|
oldFile,
|
|
341
414
|
newFile
|
|
@@ -348,6 +421,7 @@ var FileDiff = class {
|
|
|
348
421
|
fileContainer,
|
|
349
422
|
lineAnnotations,
|
|
350
423
|
fileDiff,
|
|
424
|
+
forceRender: forceEditorRender || fileInputProps.forceRender,
|
|
351
425
|
preventEmit: true
|
|
352
426
|
});
|
|
353
427
|
else this.hydrationSetup({
|
|
@@ -405,6 +479,7 @@ var FileDiff = class {
|
|
|
405
479
|
if (this.pre == null) return;
|
|
406
480
|
this.syncInteractionOptions();
|
|
407
481
|
this.hunksRenderer.hydrate(this.fileDiff);
|
|
482
|
+
this.renderedDiff = this.fileDiff;
|
|
408
483
|
this.renderAnnotations();
|
|
409
484
|
this.renderGutterUtility();
|
|
410
485
|
this.injectUnsafeCSS();
|
|
@@ -433,10 +508,15 @@ var FileDiff = class {
|
|
|
433
508
|
loadFilesIfNecessary() {
|
|
434
509
|
const { fileDiff, options: { loadDiffFiles } } = this;
|
|
435
510
|
if (fileDiff == null || loadDiffFiles == null || !canHydrateDiff(fileDiff) || this.pendingFiles?.fileDiff === fileDiff) return;
|
|
436
|
-
this.
|
|
511
|
+
const promise = this.loadFilesForDiff(fileDiff, loadDiffFiles);
|
|
512
|
+
const pendingFiles = this.pendingFiles = {
|
|
437
513
|
fileDiff,
|
|
438
|
-
promise
|
|
514
|
+
promise
|
|
515
|
+
};
|
|
516
|
+
const clearPendingFiles = () => {
|
|
517
|
+
if (this.pendingFiles === pendingFiles) this.pendingFiles = void 0;
|
|
439
518
|
};
|
|
519
|
+
pendingFiles.promise = promise.finally(clearPendingFiles);
|
|
440
520
|
}
|
|
441
521
|
async loadFilesForDiff(fileDiff, loadDiffFiles) {
|
|
442
522
|
try {
|
|
@@ -446,18 +526,74 @@ var FileDiff = class {
|
|
|
446
526
|
} catch (error) {
|
|
447
527
|
if (this.options.disableErrorHandling === true) throw error;
|
|
448
528
|
console.error(error);
|
|
449
|
-
} finally {
|
|
450
|
-
if (this.pendingFiles?.fileDiff === fileDiff) this.pendingFiles = void 0;
|
|
451
529
|
}
|
|
452
530
|
}
|
|
453
531
|
async handleFilesLoaded(expectedDiff, files) {
|
|
454
532
|
if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) return;
|
|
455
533
|
hydratePartialDiff("merge", expectedDiff, files);
|
|
456
534
|
this.setHydratedState(files);
|
|
535
|
+
if (this.startHydratedEditSession(expectedDiff)) {
|
|
536
|
+
this.rerender();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
457
539
|
await awaitWithTimeout(() => this.primeHighlightCache(expectedDiff));
|
|
458
540
|
if (!this.enabled || this.fileDiff !== expectedDiff) return;
|
|
459
541
|
this.rerender();
|
|
460
542
|
}
|
|
543
|
+
startHydratedEditSession(expectedDiff) {
|
|
544
|
+
if (expectedDiff.isPartial) throw new Error("FileDiff.startHydratedEditSession: diffs cannot be partial for editing");
|
|
545
|
+
if (this.fileDiff !== expectedDiff) return false;
|
|
546
|
+
const { editor } = this;
|
|
547
|
+
if (this.editSession?.outgoingDiff != null) {
|
|
548
|
+
this.installEditSession(expectedDiff);
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
if (editor == null || this.editSession != null) return false;
|
|
552
|
+
this.installEditSession(expectedDiff, editor.__getDocumentContents(getAdditionFile(expectedDiff)), editor.__getDocumentSessionState());
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
updateExternalDiff(incomingExternalDiff, lineAnnotations) {
|
|
556
|
+
if (areDiffTargetsEqual(this.fileDiff, incomingExternalDiff)) return false;
|
|
557
|
+
const outgoingDiff = this.editSession?.outgoingDiff ?? this.editSession?.diff;
|
|
558
|
+
this.fileDiff = incomingExternalDiff;
|
|
559
|
+
if (outgoingDiff != null) {
|
|
560
|
+
if (incomingExternalDiff.isPartial) this.loadFilesIfNecessary();
|
|
561
|
+
else this.installEditSession(incomingExternalDiff);
|
|
562
|
+
if (this.editSession != null) this.editSession.outgoingDiff = outgoingDiff;
|
|
563
|
+
} else if (this.editor != null) if (incomingExternalDiff.isPartial) this.loadFilesIfNecessary();
|
|
564
|
+
else this.installEditSession(incomingExternalDiff, this.editor.__getDocumentContents(getAdditionFile(incomingExternalDiff)), this.editor.__getDocumentSessionState());
|
|
565
|
+
if (this.editSession?.annotations != null && lineAnnotations != null) {
|
|
566
|
+
this.lineAnnotations = lineAnnotations;
|
|
567
|
+
this.editSession.annotations = adoptEditSessionAnnotations(lineAnnotations, getLineAnnotationName, this.editSession.annotations);
|
|
568
|
+
}
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
installEditSession(externalDiff, retainedDocument, retainedSession) {
|
|
572
|
+
const externalContents = externalDiff.additionLines.join("");
|
|
573
|
+
const retainedLines = retainedDocument != null ? splitFileContents(retainedDocument.contents) : void 0;
|
|
574
|
+
const restoreRetainedSession = retainedSession != null && canRestoreDiffSession(retainedSession, externalDiff);
|
|
575
|
+
if (retainedSession != null && !restoreRetainedSession) throw new Error("FileDiff: retained session cannot resume against a different old file");
|
|
576
|
+
if (retainedDocument != null && retainedDocument.contents !== externalContents && !restoreRetainedSession) throw new Error("FileDiff: retained edits are missing their diff session state");
|
|
577
|
+
const usesExternalDocument = retainedDocument == null || retainedDocument.name === externalDiff.name && retainedDocument.lang === externalDiff.lang && retainedDocument.contents === externalContents;
|
|
578
|
+
const sessionDiff = createEditSessionDiff(externalDiff);
|
|
579
|
+
if (retainedDocument != null && retainedLines != null && !usesExternalDocument) {
|
|
580
|
+
sessionDiff.name = retainedDocument.name;
|
|
581
|
+
sessionDiff.lang = retainedDocument.lang;
|
|
582
|
+
}
|
|
583
|
+
if (restoreRetainedSession && retainedSession != null && retainedLines != null) {
|
|
584
|
+
sessionDiff.additionLines = retainedLines;
|
|
585
|
+
sessionDiff.type = retainedSession.type;
|
|
586
|
+
sessionDiff.hunks = retainedSession.hunks;
|
|
587
|
+
sessionDiff.editSessionDirty = true;
|
|
588
|
+
recomputeDiffRenderLineCounts(sessionDiff);
|
|
589
|
+
}
|
|
590
|
+
this.editSession = {
|
|
591
|
+
diff: sessionDiff,
|
|
592
|
+
annotations: this.editSession?.annotations ?? adoptEditSessionAnnotations(this.lineAnnotations, getLineAnnotationName),
|
|
593
|
+
outgoingDiff: this.editSession?.outgoingDiff
|
|
594
|
+
};
|
|
595
|
+
this.hunksRenderer.beginEditSession(sessionDiff, usesExternalDocument && !restoreRetainedSession ? externalDiff : void 0);
|
|
596
|
+
}
|
|
461
597
|
setHydratedState(files) {
|
|
462
598
|
this.deletionFile = files.oldFile;
|
|
463
599
|
this.additionFile = files.newFile;
|
|
@@ -465,20 +601,23 @@ var FileDiff = class {
|
|
|
465
601
|
this.hunksRenderer.clearRenderCache();
|
|
466
602
|
}
|
|
467
603
|
render({ fileDiff, deferManagers = false, forceRender = false, preventEmit = false, lineAnnotations, fileContainer, containerWrapper, renderRange, ...fileInputProps }) {
|
|
604
|
+
if (!this.enabled) throw new Error("FileDiff.render: attempting to call render after cleaned up");
|
|
468
605
|
const fileInput = getDiffFileInput(fileInputProps, "FileDiff.render");
|
|
469
606
|
const oldFile = fileInput?.oldFile;
|
|
470
607
|
const newFile = fileInput?.newFile;
|
|
471
|
-
if (!this.enabled) throw new Error("FileDiff.render: attempting to call render after cleaned up");
|
|
472
|
-
if (fileDiff != null && fileDiff.cacheKey === void 0) fileDiff.cacheKey = fileDiff.prevName != null ? fileDiff.prevName + ":" + fileDiff.name : fileDiff.name;
|
|
473
608
|
this.editor?.__postponeBgTokenizeToNextFrame();
|
|
474
609
|
const { collapsed = false, themeType = "system", expandUnchanged = false } = this.options;
|
|
475
610
|
const nextRenderRange = collapsed ? void 0 : renderRange;
|
|
476
611
|
const themeChanged = this.hasThemeChanged();
|
|
477
612
|
const hasFileInput = fileInput != null;
|
|
478
613
|
const filesDidChange = hasFileInput && (!areOptionalFilesEqual(oldFile, this.deletionFile) || !areOptionalFilesEqual(newFile, this.additionFile));
|
|
479
|
-
let diffDidChange = fileDiff != null && fileDiff
|
|
480
|
-
const annotationsChanged = lineAnnotations != null && (lineAnnotations.length > 0 || this.
|
|
481
|
-
if (!collapsed && areRenderRangesEqual(nextRenderRange, this.renderRange) && !forceRender && !annotationsChanged && !themeChanged && (fileDiff != null &&
|
|
614
|
+
let diffDidChange = fileDiff != null && !areDiffTargetsEqual(fileDiff, this.fileDiff);
|
|
615
|
+
const annotationsChanged = lineAnnotations != null && (lineAnnotations.length > 0 || this.getLatestAnnotations().length > 0) ? this.isNewAnnotations(lineAnnotations) : false;
|
|
616
|
+
if (!collapsed && areRenderRangesEqual(nextRenderRange, this.renderRange) && !forceRender && !annotationsChanged && !themeChanged && (fileDiff != null && !diffDidChange || fileDiff == null && !filesDidChange)) {
|
|
617
|
+
const rendered = this.applyCachedThemeState(themeType);
|
|
618
|
+
if (rendered) this.finalizeRender();
|
|
619
|
+
return rendered;
|
|
620
|
+
}
|
|
482
621
|
let nextParsedFileDiff;
|
|
483
622
|
if (fileDiff == null && hasFileInput && (filesDidChange || this.fileDiff == null)) nextParsedFileDiff = parseDiffFromFile(fileInput.oldFile, fileInput.newFile, this.options.parseDiffOptions);
|
|
484
623
|
const { renderRange: previousRenderRange } = this;
|
|
@@ -490,28 +629,29 @@ var FileDiff = class {
|
|
|
490
629
|
this.deletionFile = void 0;
|
|
491
630
|
this.additionFile = void 0;
|
|
492
631
|
}
|
|
493
|
-
if (fileDiff != null) this.fileDiff
|
|
632
|
+
if (fileDiff != null && diffDidChange) this.updateExternalDiff(fileDiff, lineAnnotations);
|
|
494
633
|
else if (nextParsedFileDiff != null) {
|
|
495
634
|
diffDidChange = true;
|
|
496
|
-
this.
|
|
635
|
+
this.updateExternalDiff(nextParsedFileDiff, lineAnnotations);
|
|
497
636
|
}
|
|
498
|
-
if (diffDidChange) this.
|
|
637
|
+
if (diffDidChange) this.clearReusableHeader();
|
|
499
638
|
if (lineAnnotations != null) this.setLineAnnotations(lineAnnotations);
|
|
500
|
-
|
|
501
|
-
if (
|
|
502
|
-
|
|
639
|
+
const latestDiff = this.getLatestDiff();
|
|
640
|
+
if (latestDiff == null) return false;
|
|
641
|
+
if (latestDiff.editSessionDirty === true && this.shouldSelfHealEditSession()) {
|
|
642
|
+
finishEditSessionForDiff(latestDiff, this.options.parseDiffOptions);
|
|
503
643
|
this.hunksRenderer.refreshHighlightedResult();
|
|
504
644
|
}
|
|
505
645
|
if (expandUnchanged) this.loadFilesIfNecessary();
|
|
506
646
|
this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options));
|
|
507
647
|
this.syncInteractionOptions();
|
|
508
|
-
this.hunksRenderer.setLineAnnotations(this.
|
|
648
|
+
this.hunksRenderer.setLineAnnotations(this.getLatestAnnotations());
|
|
509
649
|
const { disableErrorHandling = false, disableFileHeader = false } = this.options;
|
|
510
650
|
if (disableFileHeader) {
|
|
511
651
|
if (this.headerElement != null) {
|
|
512
652
|
this.headerElement.remove();
|
|
513
653
|
this.headerElement = void 0;
|
|
514
|
-
this.
|
|
654
|
+
this.headerCache.lastRenderedHTML = void 0;
|
|
515
655
|
}
|
|
516
656
|
this.clearHeaderSlots();
|
|
517
657
|
}
|
|
@@ -521,38 +661,42 @@ var FileDiff = class {
|
|
|
521
661
|
this.removeRenderedCode();
|
|
522
662
|
this.clearAuxiliaryNodes();
|
|
523
663
|
try {
|
|
524
|
-
const hunksResult = this.hunksRenderer.renderDiff(
|
|
664
|
+
const hunksResult = this.hunksRenderer.renderDiff(latestDiff, EMPTY_RENDER_RANGE);
|
|
525
665
|
if (hunksResult != null) this.applyThemeState(fileContainer, hunksResult.themeStyles, themeType, hunksResult.baseThemeType);
|
|
526
|
-
if (hunksResult?.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer);
|
|
666
|
+
if (hunksResult?.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer, hunksResult.fileDiff);
|
|
527
667
|
this.renderSeparators([]);
|
|
668
|
+
this.renderedDiff = hunksResult?.fileDiff ?? latestDiff;
|
|
528
669
|
this.injectUnsafeCSS();
|
|
529
670
|
} catch (error) {
|
|
530
671
|
if (disableErrorHandling) throw error;
|
|
531
672
|
console.error(error);
|
|
532
673
|
if (error instanceof Error) this.applyErrorToDOM(error, fileContainer);
|
|
533
674
|
}
|
|
675
|
+
this.finalizeRender();
|
|
534
676
|
if (!preventEmit) this.emitPostRender();
|
|
535
677
|
return true;
|
|
536
678
|
}
|
|
537
679
|
try {
|
|
538
680
|
const pre = this.getOrCreatePreNode(fileContainer);
|
|
539
|
-
if (!(this.canPartiallyRender(forceRender, annotationsChanged, filesDidChange || diffDidChange || themeChanged) && this.applyPartialRender({
|
|
681
|
+
if (!(this.canPartiallyRender(forceRender, annotationsChanged, filesDidChange || diffDidChange || themeChanged || !areDiffTargetsEqual(this.renderedDiff, latestDiff)) && this.applyPartialRender({
|
|
682
|
+
fileDiff: latestDiff,
|
|
540
683
|
previousRenderRange,
|
|
541
684
|
renderRange: nextRenderRange
|
|
542
685
|
}))) {
|
|
543
|
-
const hunksResult = this.hunksRenderer.renderDiff(
|
|
686
|
+
const hunksResult = this.hunksRenderer.renderDiff(latestDiff, nextRenderRange);
|
|
544
687
|
if (hunksResult == null) {
|
|
545
|
-
if (this.workerManager?.isInitialized() === false) this.workerManager.initialize().then(() => this.rerender());
|
|
688
|
+
if (this.workerManager?.isInitialized() === false && this.workerManager.isWorkingPool()) this.workerManager.initialize().catch(() => {}).then(() => this.rerender());
|
|
546
689
|
return false;
|
|
547
690
|
}
|
|
548
691
|
this.applyThemeState(fileContainer, hunksResult.themeStyles, themeType, hunksResult.baseThemeType);
|
|
549
|
-
if (hunksResult.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer);
|
|
692
|
+
if (hunksResult.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer, hunksResult.fileDiff);
|
|
550
693
|
if (hunksResult.additionsContentAST != null || hunksResult.deletionsContentAST != null || hunksResult.unifiedContentAST != null) this.applyHunksToDOM(pre, hunksResult);
|
|
551
694
|
else if (this.pre != null) {
|
|
552
695
|
this.pre.remove();
|
|
553
696
|
this.pre = void 0;
|
|
554
697
|
}
|
|
555
698
|
this.renderSeparators(hunksResult.hunkData);
|
|
699
|
+
this.renderedDiff = hunksResult.fileDiff;
|
|
556
700
|
}
|
|
557
701
|
this.applyBuffers(pre, nextRenderRange);
|
|
558
702
|
this.injectUnsafeCSS();
|
|
@@ -560,6 +704,7 @@ var FileDiff = class {
|
|
|
560
704
|
this.renderGutterUtility();
|
|
561
705
|
this.managersDirty = true;
|
|
562
706
|
if (!deferManagers) this.flushManagers();
|
|
707
|
+
this.finalizeRender();
|
|
563
708
|
if (this.editor != null) this.syncRenderViewToEditor();
|
|
564
709
|
} catch (error) {
|
|
565
710
|
if (disableErrorHandling) throw error;
|
|
@@ -569,6 +714,7 @@ var FileDiff = class {
|
|
|
569
714
|
if (!preventEmit) this.emitPostRender();
|
|
570
715
|
return true;
|
|
571
716
|
}
|
|
717
|
+
finalizeRender() {}
|
|
572
718
|
emitPostRender(unmount = false) {
|
|
573
719
|
const { fileContainer, options: { onPostRender } } = this;
|
|
574
720
|
if (unmount) {
|
|
@@ -583,22 +729,49 @@ var FileDiff = class {
|
|
|
583
729
|
this.mounted = true;
|
|
584
730
|
onPostRender?.(fileContainer, this, phase);
|
|
585
731
|
}
|
|
586
|
-
|
|
587
|
-
return this.
|
|
732
|
+
getLatestDiff(fileDiff = this.fileDiff) {
|
|
733
|
+
return this.editSession?.diff ?? fileDiff;
|
|
734
|
+
}
|
|
735
|
+
getRenderedDiff() {
|
|
736
|
+
return this.renderedDiff;
|
|
588
737
|
}
|
|
589
738
|
syncRenderViewToEditor() {
|
|
590
|
-
const editor = this
|
|
591
|
-
const
|
|
592
|
-
const fileDiff = this.fileDiffCache;
|
|
593
|
-
const lineAnnotations = this.lineAnnotations;
|
|
739
|
+
const { editor, fileContainer } = this;
|
|
740
|
+
const lineAnnotations = this.getLatestAnnotations();
|
|
594
741
|
const renderRange = this.computeEditorRenderRange(this.renderRange);
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
742
|
+
const fileDiff = this.getLatestDiff();
|
|
743
|
+
if (editor == null || fileContainer == null || fileDiff == null || fileDiff.isPartial) return;
|
|
744
|
+
const sync = (highlighter) => {
|
|
745
|
+
if (!this.enabled || this.editor !== editor || this.fileContainer !== fileContainer || this.getLatestDiff() !== fileDiff) return;
|
|
746
|
+
const replacement = this.editSession?.outgoingDiff;
|
|
747
|
+
const externalDiff = this.fileDiff;
|
|
748
|
+
const externalDocument = replacement != null && externalDiff != null && replacement !== fileDiff;
|
|
749
|
+
const resetHistory = externalDocument ? shouldResetUndoState(replacement, externalDiff) : false;
|
|
750
|
+
editor.__syncRenderView({
|
|
751
|
+
highlighter,
|
|
752
|
+
fileContainer,
|
|
753
|
+
fileDiff,
|
|
754
|
+
lineAnnotations,
|
|
755
|
+
renderRange,
|
|
756
|
+
externalDocument,
|
|
757
|
+
resetHistory
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
const theme = this.getTheme();
|
|
761
|
+
const lang = fileDiff.lang ?? getFiletypeFromFileName(fileDiff.name);
|
|
762
|
+
const highlighter = getHighlighterIfLoaded({
|
|
763
|
+
theme,
|
|
764
|
+
lang
|
|
598
765
|
});
|
|
766
|
+
if (highlighter != null) sync(highlighter);
|
|
767
|
+
else getSharedHighlighter({
|
|
768
|
+
themes: getThemes(theme),
|
|
769
|
+
langs: ["text", lang],
|
|
770
|
+
preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
|
|
771
|
+
}).then(sync);
|
|
599
772
|
}
|
|
600
773
|
computeEditorRenderRange(renderRange) {
|
|
601
|
-
const fileDiff = this.
|
|
774
|
+
const fileDiff = this.getLatestDiff();
|
|
602
775
|
if (renderRange == null || fileDiff == null || isDefaultRenderRange(renderRange)) return renderRange;
|
|
603
776
|
const { diffStyle = "split", expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
|
|
604
777
|
let firstLineNumber;
|
|
@@ -628,37 +801,172 @@ var FileDiff = class {
|
|
|
628
801
|
totalLines: lastLineNumber - firstLineNumber + 1
|
|
629
802
|
};
|
|
630
803
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
this.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
804
|
+
/** @internal The editor applied or edited past the pending external replacement. */
|
|
805
|
+
__acknowledgeDocumentUpdate() {
|
|
806
|
+
if (this.editSession != null) this.editSession.outgoingDiff = void 0;
|
|
807
|
+
}
|
|
808
|
+
/** @internal Settle annotations locally. */
|
|
809
|
+
__acceptEditorChange(event) {
|
|
810
|
+
const { lineAnnotations } = event;
|
|
811
|
+
if (lineAnnotations != null) this.syncEditSessionAnnotationsFromEditor(lineAnnotations);
|
|
812
|
+
}
|
|
813
|
+
emitEditChange(event) {
|
|
814
|
+
const { onEditChange } = this.options;
|
|
815
|
+
onEditChange?.(event);
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* @internal Capture the current diff session, or return `undefined` when no
|
|
819
|
+
* complete compatible session exists.
|
|
820
|
+
*
|
|
821
|
+
* When `clone` is true, the returned lines and hunks are copied.
|
|
822
|
+
*/
|
|
823
|
+
__captureDocumentSessionState(clone = true) {
|
|
824
|
+
let { fileDiff, editSession: { diff: sessionDiff, outgoingDiff } = {} } = this;
|
|
825
|
+
if (outgoingDiff != null && fileDiff != null) {
|
|
826
|
+
if (!fileDiff.isPartial && shouldResetUndoState(outgoingDiff, fileDiff)) return;
|
|
827
|
+
sessionDiff = outgoingDiff;
|
|
828
|
+
}
|
|
829
|
+
if (sessionDiff == null || sessionDiff.isPartial) return;
|
|
830
|
+
return {
|
|
831
|
+
diffSession: {
|
|
832
|
+
oldFile: sessionDiff.type !== "new" ? {
|
|
833
|
+
name: sessionDiff.prevName ?? sessionDiff.name,
|
|
834
|
+
lines: clone ? [...sessionDiff.deletionLines] : sessionDiff.deletionLines
|
|
835
|
+
} : null,
|
|
836
|
+
type: sessionDiff.type,
|
|
837
|
+
hunks: clone ? cloneHunks(sessionDiff.hunks) : sessionDiff.hunks
|
|
838
|
+
},
|
|
839
|
+
hasChanges: sessionDiff.editSessionDirty === true
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
/** @internal Associate this component with its editor for a render lifecycle. */
|
|
843
|
+
__attachEditor(editor) {
|
|
844
|
+
if (this.type !== "file-diff") throw new Error(`FileDiff.__attachEditor: cannot attach an editor to a "${this.type}" diff`);
|
|
845
|
+
if (this.editor != null) throw new Error("FileDiff.__attachEditor: an editor is already attached");
|
|
846
|
+
const detach = () => {
|
|
640
847
|
this.editor = void 0;
|
|
641
|
-
|
|
848
|
+
this.finishEditSession();
|
|
642
849
|
};
|
|
850
|
+
try {
|
|
851
|
+
this.resumeEditorRendering(editor);
|
|
852
|
+
return detach;
|
|
853
|
+
} catch (error) {
|
|
854
|
+
detach();
|
|
855
|
+
throw error;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/** @internal Resume rendering for the editor already associated with this component. */
|
|
859
|
+
__resumeEditor(editor) {
|
|
860
|
+
if (this.editor !== editor) throw new Error("FileDiff.__resumeEditor: editor association changed");
|
|
861
|
+
this.resumeEditorRendering(editor);
|
|
862
|
+
}
|
|
863
|
+
resumeEditorRendering(editor) {
|
|
864
|
+
const { fileDiff: externalDiff } = this;
|
|
865
|
+
const pendingReplacement = this.editSession?.outgoingDiff;
|
|
866
|
+
if (pendingReplacement != null && externalDiff != null && !externalDiff.isPartial && this.editSession?.diff === pendingReplacement) this.installEditSession(externalDiff);
|
|
867
|
+
const initialExternalDiff = this.editSession == null && externalDiff != null && !externalDiff.isPartial ? externalDiff : void 0;
|
|
868
|
+
if (initialExternalDiff != null) this.installEditSession(initialExternalDiff, editor.__getDocumentContents(getAdditionFile(initialExternalDiff)), editor.__getDocumentSessionState());
|
|
869
|
+
else if (this.editSession != null) this.hunksRenderer.beginEditSession(this.editSession.diff);
|
|
870
|
+
this.editor = editor;
|
|
871
|
+
if (this.fileDiff?.isPartial === true) this.loadFilesIfNecessary();
|
|
872
|
+
const editSessionDiff = this.editSession?.diff;
|
|
873
|
+
if (this.hunksRenderer.editorRenderReady()) {
|
|
874
|
+
if (editSessionDiff != null && this.hunksRenderer.diffCache === editSessionDiff) this.renderedDiff = editSessionDiff;
|
|
875
|
+
this.syncRenderViewToEditor();
|
|
876
|
+
} else this.rerender();
|
|
643
877
|
}
|
|
644
878
|
finishEditSession() {
|
|
645
879
|
this.hunksRenderer.endEditSession();
|
|
646
|
-
this.
|
|
880
|
+
this.finalizeEditSessionHunks();
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* @internal
|
|
884
|
+
*
|
|
885
|
+
* Ends the edit session and settles which diff this component renders.
|
|
886
|
+
* Requires the editor to be detached first. Does nothing when no session
|
|
887
|
+
* exists, so callers can invoke it again safely after it has settled.
|
|
888
|
+
*
|
|
889
|
+
* `onEditComplete` receives the completed diff, current external diff,
|
|
890
|
+
* complete file pair, and both annotation collections even when the final
|
|
891
|
+
* text is unchanged. In `install` mode, accepting installs the completed diff
|
|
892
|
+
* and its annotations; rejecting or having no handler restores the external
|
|
893
|
+
* values. `discard` mode always restores the external values. An accepted
|
|
894
|
+
* diff cannot reuse the replaced diff's `cacheKey`.
|
|
895
|
+
*/
|
|
896
|
+
__completeEditSession(editor, mode) {
|
|
897
|
+
this.settleEditSession(mode === "install", editor);
|
|
898
|
+
}
|
|
899
|
+
settleEditSession(installResult, editor) {
|
|
900
|
+
const { editSession, fileDiff: externalDiff, lineAnnotations: externalAnnotations } = this;
|
|
901
|
+
if (editSession == null || externalDiff == null) return;
|
|
902
|
+
const { diff: editSessionDiff, annotations: editSessionAnnotations } = editSession;
|
|
903
|
+
if (this.editor != null) throw new Error("FileDiff.__completeEditSession: detach the editor before completing the session");
|
|
904
|
+
this.hunksRenderer.endEditSession();
|
|
905
|
+
this.finalizeEditSessionHunks();
|
|
906
|
+
const sessionAnnotationsCurrent = editSessionAnnotations?.current;
|
|
907
|
+
let acceptedDiff;
|
|
908
|
+
let acceptedOldFile = null;
|
|
909
|
+
let acceptedNewFile = null;
|
|
910
|
+
let failed = false;
|
|
911
|
+
let failure;
|
|
912
|
+
if (editor == null) throw new Error("FileDiff.__completeEditSession: editor is required for completion");
|
|
913
|
+
const completedDiff = cloneFileDiffMetadata(editSessionDiff);
|
|
914
|
+
const newFile = {
|
|
915
|
+
name: completedDiff.name,
|
|
916
|
+
contents: completedDiff.additionLines.join("")
|
|
917
|
+
};
|
|
918
|
+
if (completedDiff.lang != null) newFile.lang = completedDiff.lang;
|
|
919
|
+
const event = {
|
|
920
|
+
fileDiff: completedDiff,
|
|
921
|
+
editor,
|
|
922
|
+
originalFileDiff: externalDiff,
|
|
923
|
+
oldFile: completedDiff.type === "new" ? null : {
|
|
924
|
+
name: completedDiff.prevName ?? completedDiff.name,
|
|
925
|
+
contents: completedDiff.deletionLines.join("")
|
|
926
|
+
},
|
|
927
|
+
newFile,
|
|
928
|
+
lineAnnotations: sessionAnnotationsCurrent,
|
|
929
|
+
originalLineAnnotations: externalAnnotations
|
|
930
|
+
};
|
|
931
|
+
Object.freeze(event);
|
|
932
|
+
try {
|
|
933
|
+
editor.__emitEditComplete(event);
|
|
934
|
+
if (this.options.onEditComplete?.(event) === "accept") {
|
|
935
|
+
if (completedDiff.cacheKey != null && completedDiff.cacheKey === externalDiff.cacheKey) throw new Error("FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey");
|
|
936
|
+
acceptedDiff = completedDiff;
|
|
937
|
+
acceptedOldFile = event.oldFile;
|
|
938
|
+
acceptedNewFile = event.newFile;
|
|
939
|
+
}
|
|
940
|
+
} catch (error) {
|
|
941
|
+
failed = true;
|
|
942
|
+
failure = error;
|
|
943
|
+
}
|
|
944
|
+
if (installResult && acceptedDiff != null) {
|
|
945
|
+
this.fileDiff = acceptedDiff;
|
|
946
|
+
if (this.additionFile != null) {
|
|
947
|
+
this.deletionFile = acceptedOldFile;
|
|
948
|
+
this.additionFile = acceptedNewFile;
|
|
949
|
+
}
|
|
950
|
+
if (sessionAnnotationsCurrent != null) this.lineAnnotations = sessionAnnotationsCurrent;
|
|
951
|
+
}
|
|
952
|
+
this.editSession = void 0;
|
|
953
|
+
if (installResult && this.fileContainer != null) this.rerender();
|
|
954
|
+
if (failed) throw failure;
|
|
647
955
|
}
|
|
648
956
|
/**
|
|
649
|
-
* Run the
|
|
957
|
+
* Run the session-end recompute: restore recompute-shaped hunks (a
|
|
650
958
|
* context-only region collapses away, boundaries re-derive), preserve
|
|
651
959
|
* expansion state best-effort via old-side anchors, and repaint through
|
|
652
960
|
* the session render path — which also invalidates virtualized layout,
|
|
653
961
|
* since nothing else does at exit now that editing does not flip
|
|
654
962
|
* expandUnchanged. Marker-guarded and idempotent; CodeView also calls this
|
|
655
|
-
* when
|
|
963
|
+
* when ending a session whose detach closure was consumed by a recycle.
|
|
656
964
|
* Safe on a cleaned-up instance: the recompute is pure metadata work and
|
|
657
965
|
* the deferred rerender is enabled-guarded. Returns true when a recompute
|
|
658
966
|
* ran.
|
|
659
967
|
*/
|
|
660
|
-
|
|
661
|
-
const fileDiff = this.
|
|
968
|
+
finalizeEditSessionHunks() {
|
|
969
|
+
const fileDiff = this.getLatestDiff();
|
|
662
970
|
if (fileDiff == null || fileDiff.editSessionDirty !== true) return false;
|
|
663
971
|
const { collapsedContextThreshold = 1 } = this.options;
|
|
664
972
|
const anchors = captureExpansionAnchors(fileDiff, this.hunksRenderer.getExpandedHunksMap(), collapsedContextThreshold);
|
|
@@ -669,22 +977,20 @@ var FileDiff = class {
|
|
|
669
977
|
return true;
|
|
670
978
|
}
|
|
671
979
|
applyDocumentChange(textDocument, newLineAnnotations) {
|
|
980
|
+
const editSessionDiff = this.editSession?.diff;
|
|
981
|
+
if (editSessionDiff == null) throw new Error("FileDiff.applyDocumentChange: requires an active edit session");
|
|
982
|
+
this.detachAdditionLines();
|
|
983
|
+
this.hunksRenderer.beginEditSession(editSessionDiff);
|
|
672
984
|
this.hunksRenderer.applyDocumentChange(textDocument);
|
|
673
|
-
|
|
674
|
-
if (fileDiff != null) {
|
|
675
|
-
const cacheKey = this.fileDiff?.cacheKey;
|
|
676
|
-
if (cacheKey != null && fileDiff.cacheKey == null) fileDiff.cacheKey = cacheKey;
|
|
677
|
-
this.fileDiff = fileDiff;
|
|
678
|
-
}
|
|
679
|
-
if (newLineAnnotations !== void 0 && newLineAnnotations !== this.lineAnnotations) {
|
|
680
|
-
this.setLineAnnotations(newLineAnnotations);
|
|
681
|
-
this.hunksRenderer.setLineAnnotations(this.lineAnnotations);
|
|
682
|
-
this.renderAnnotations();
|
|
683
|
-
}
|
|
985
|
+
if (newLineAnnotations != null) this.syncEditSessionAnnotationsFromEditor(newLineAnnotations);
|
|
684
986
|
this.rerender();
|
|
685
987
|
this.interactionManager.setSelectionDirty();
|
|
686
988
|
}
|
|
687
989
|
updateRenderCache(dirtyLines, themeType, options = {}) {
|
|
990
|
+
const editSessionDiff = this.editSession?.diff;
|
|
991
|
+
if (editSessionDiff == null) throw new Error("FileDiff.updateRenderCache: requires an active edit session");
|
|
992
|
+
this.detachAdditionLines();
|
|
993
|
+
this.hunksRenderer.beginEditSession(editSessionDiff);
|
|
688
994
|
const { shouldRefreshDiffsView, lineCountChangeInFlight } = options;
|
|
689
995
|
if (this.hunksRenderer.updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight)) {
|
|
690
996
|
if (this.refreshViewTimeout != null) {
|
|
@@ -706,8 +1012,13 @@ var FileDiff = class {
|
|
|
706
1012
|
}, 150);
|
|
707
1013
|
}
|
|
708
1014
|
}
|
|
1015
|
+
detachAdditionLines() {
|
|
1016
|
+
const editSessionDiff = this.editSession?.diff;
|
|
1017
|
+
const { fileDiff } = this;
|
|
1018
|
+
if (editSessionDiff != null && (editSessionDiff.additionLines === fileDiff?.additionLines || editSessionDiff.additionLines === editSessionDiff.deletionLines)) editSessionDiff.additionLines = [...editSessionDiff.additionLines];
|
|
1019
|
+
}
|
|
709
1020
|
isLineRenderable(lineNumber) {
|
|
710
|
-
const fileDiff = this.
|
|
1021
|
+
const fileDiff = this.getRenderedDiff();
|
|
711
1022
|
if (fileDiff == null) return true;
|
|
712
1023
|
const { expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
|
|
713
1024
|
return isAdditionLineRenderable({
|
|
@@ -718,7 +1029,7 @@ var FileDiff = class {
|
|
|
718
1029
|
});
|
|
719
1030
|
}
|
|
720
1031
|
getNearestRenderableLine(lineNumber, direction) {
|
|
721
|
-
const fileDiff = this.
|
|
1032
|
+
const fileDiff = this.getRenderedDiff();
|
|
722
1033
|
if (fileDiff == null) return lineNumber;
|
|
723
1034
|
const { expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
|
|
724
1035
|
return getNearestRenderableAdditionLine({
|
|
@@ -730,7 +1041,7 @@ var FileDiff = class {
|
|
|
730
1041
|
});
|
|
731
1042
|
}
|
|
732
1043
|
revealLine(lineNumber) {
|
|
733
|
-
const fileDiff = this.
|
|
1044
|
+
const fileDiff = this.getRenderedDiff();
|
|
734
1045
|
const { expandUnchanged = false, collapsedContextThreshold = 1, expansionLineCount = 100 } = this.options;
|
|
735
1046
|
if (fileDiff == null || fileDiff.isPartial || expandUnchanged) return false;
|
|
736
1047
|
const expandedHunks = this.hunksRenderer.getExpandedHunksMap();
|
|
@@ -865,7 +1176,7 @@ var FileDiff = class {
|
|
|
865
1176
|
this.hasAdoptedThemeCSS = false;
|
|
866
1177
|
this.unsafeCSSStyle = void 0;
|
|
867
1178
|
this.appliedUnsafeCSS = void 0;
|
|
868
|
-
this.
|
|
1179
|
+
this.headerCache.lastRenderedHTML = void 0;
|
|
869
1180
|
this.lastRowCount = void 0;
|
|
870
1181
|
this.mounted = false;
|
|
871
1182
|
}
|
|
@@ -909,15 +1220,17 @@ var FileDiff = class {
|
|
|
909
1220
|
}
|
|
910
1221
|
const staleAnnotations = new Map(this.annotationCache);
|
|
911
1222
|
const { renderAnnotation } = this.options;
|
|
912
|
-
|
|
913
|
-
|
|
1223
|
+
const lineAnnotations = this.getLatestAnnotations();
|
|
1224
|
+
if (renderAnnotation != null && lineAnnotations.length > 0) for (const [index, annotation] of lineAnnotations.entries()) {
|
|
1225
|
+
const name = this.getAnnotationSlotName(annotation);
|
|
1226
|
+
const id = `${index}-${name}`;
|
|
914
1227
|
let cache = this.annotationCache.get(id);
|
|
915
1228
|
if (cache == null || !areDiffLineAnnotationsEqual(annotation, cache.annotation)) {
|
|
916
1229
|
cache?.element.remove();
|
|
917
1230
|
const content = renderAnnotation(annotation);
|
|
918
1231
|
if (content == null) continue;
|
|
919
1232
|
cache = {
|
|
920
|
-
element: createAnnotationWrapperNode(
|
|
1233
|
+
element: createAnnotationWrapperNode(name),
|
|
921
1234
|
annotation
|
|
922
1235
|
};
|
|
923
1236
|
cache.element.appendChild(content);
|
|
@@ -958,7 +1271,7 @@ var FileDiff = class {
|
|
|
958
1271
|
if (containerChanged) this.emitPostRender(true);
|
|
959
1272
|
this.fileContainer = nextContainer;
|
|
960
1273
|
if (previousContainer != null && containerChanged) {
|
|
961
|
-
this.
|
|
1274
|
+
this.headerCache.lastRenderedHTML = void 0;
|
|
962
1275
|
this.headerElement = void 0;
|
|
963
1276
|
}
|
|
964
1277
|
if (parentNode != null && this.fileContainer.parentNode !== parentNode) parentNode.appendChild(this.fileContainer);
|
|
@@ -1017,14 +1330,15 @@ var FileDiff = class {
|
|
|
1017
1330
|
else if (child.hasAttribute("data-additions")) this.codeAdditions = child;
|
|
1018
1331
|
}
|
|
1019
1332
|
}
|
|
1020
|
-
applyHeaderToDOM(headerAST, container) {
|
|
1333
|
+
applyHeaderToDOM(headerAST, container, fileDiff) {
|
|
1021
1334
|
this.cleanupErrorWrapper();
|
|
1022
1335
|
this.placeHolder?.remove();
|
|
1023
1336
|
this.placeHolder = void 0;
|
|
1024
|
-
const { fileDiff } = this;
|
|
1025
|
-
const headerHTML = this.cachedHeaderHTML ?? toHtml(headerAST);
|
|
1026
|
-
this.
|
|
1027
|
-
|
|
1337
|
+
const { headerCache: { fileDiff: cachedHeaderDiff, html: cachedHeaderHTML, lastRenderedHTML } } = this;
|
|
1338
|
+
const headerHTML = (fileDiff !== this.editSession?.diff && areDiffTargetsEqual(cachedHeaderDiff, fileDiff) ? cachedHeaderHTML : void 0) ?? toHtml(headerAST);
|
|
1339
|
+
this.headerCache.html = headerHTML;
|
|
1340
|
+
this.headerCache.fileDiff = fileDiff;
|
|
1341
|
+
if (headerHTML !== lastRenderedHTML) {
|
|
1028
1342
|
const tempDiv = document.createElement("div");
|
|
1029
1343
|
tempDiv.innerHTML = headerHTML;
|
|
1030
1344
|
const newHeader = tempDiv.firstElementChild;
|
|
@@ -1032,9 +1346,9 @@ var FileDiff = class {
|
|
|
1032
1346
|
if (this.headerElement != null) container.shadowRoot?.replaceChild(newHeader, this.headerElement);
|
|
1033
1347
|
else container.shadowRoot?.prepend(newHeader);
|
|
1034
1348
|
this.headerElement = newHeader;
|
|
1035
|
-
this.
|
|
1349
|
+
this.headerCache.lastRenderedHTML = headerHTML;
|
|
1036
1350
|
}
|
|
1037
|
-
if (this.isContainerManaged
|
|
1351
|
+
if (this.isContainerManaged) return;
|
|
1038
1352
|
const { renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata } = this.options;
|
|
1039
1353
|
if (renderCustomHeader != null) {
|
|
1040
1354
|
const content = renderCustomHeader(fileDiff) ?? void 0;
|
|
@@ -1056,6 +1370,10 @@ var FileDiff = class {
|
|
|
1056
1370
|
this.headerCustom?.remove();
|
|
1057
1371
|
this.headerCustom = void 0;
|
|
1058
1372
|
}
|
|
1373
|
+
clearReusableHeader() {
|
|
1374
|
+
this.headerCache.html = void 0;
|
|
1375
|
+
this.headerCache.fileDiff = void 0;
|
|
1376
|
+
}
|
|
1059
1377
|
clearHeaderSlots() {
|
|
1060
1378
|
this.headerPrefix?.remove();
|
|
1061
1379
|
this.headerFilenameSuffix?.remove();
|
|
@@ -1107,7 +1425,7 @@ var FileDiff = class {
|
|
|
1107
1425
|
applyThemeState(container, themeStyles, themeType, baseThemeType) {
|
|
1108
1426
|
const shadowRoot = container.shadowRoot ?? container.attachShadow({ mode: "open" });
|
|
1109
1427
|
const effectiveThemeType = baseThemeType ?? themeType;
|
|
1110
|
-
const currentTheme = this.
|
|
1428
|
+
const currentTheme = this.getTheme();
|
|
1111
1429
|
const theme = typeof currentTheme === "string" ? currentTheme : { ...currentTheme };
|
|
1112
1430
|
const scrollbarGutter = getMeasuredScrollbarGutter(shadowRoot);
|
|
1113
1431
|
if (this.themeCSSStyle?.parentNode === shadowRoot && this.appliedThemeCSS?.themeStyles === themeStyles && this.appliedThemeCSS.themeType === effectiveThemeType && this.appliedThemeCSS.scrollbarGutter === scrollbarGutter) {
|
|
@@ -1235,7 +1553,7 @@ var FileDiff = class {
|
|
|
1235
1553
|
else if (shouldReplace) pre.replaceChildren(...codeElements);
|
|
1236
1554
|
this.lastRowCount = result.rowCount;
|
|
1237
1555
|
}
|
|
1238
|
-
applyPartialRender({ previousRenderRange, renderRange }) {
|
|
1556
|
+
applyPartialRender({ fileDiff, previousRenderRange, renderRange }) {
|
|
1239
1557
|
const { pre, codeUnified, codeAdditions, codeDeletions, options: { diffStyle = "split" } } = this;
|
|
1240
1558
|
if (pre == null || previousRenderRange == null || renderRange == null || !Number.isFinite(previousRenderRange.totalLines) || !Number.isFinite(renderRange.totalLines) || this.lastRowCount == null) return false;
|
|
1241
1559
|
const codeElements = this.getCodeColumns(diffStyle, codeUnified, codeDeletions, codeAdditions);
|
|
@@ -1262,8 +1580,8 @@ var FileDiff = class {
|
|
|
1262
1580
|
if (this.lastRowCount < trimResult) throw new Error("FileDiff.applyPartialRender: trimmed beyond DOM row count");
|
|
1263
1581
|
let rowCount = this.lastRowCount - trimResult;
|
|
1264
1582
|
const renderChunk = (startingLine, totalLines) => {
|
|
1265
|
-
if (totalLines <= 0
|
|
1266
|
-
return this.hunksRenderer.renderDiff(
|
|
1583
|
+
if (totalLines <= 0) return;
|
|
1584
|
+
return this.hunksRenderer.renderDiff(fileDiff, {
|
|
1267
1585
|
startingLine,
|
|
1268
1586
|
totalLines,
|
|
1269
1587
|
bufferBefore: 0,
|
|
@@ -1280,6 +1598,7 @@ var FileDiff = class {
|
|
|
1280
1598
|
else if (diffStyle === "split" && Array.isArray(codeElements)) this.insertPartialHTML(diffStyle, codeElements, result, insertPosition);
|
|
1281
1599
|
else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");
|
|
1282
1600
|
rowCount += result.rowCount;
|
|
1601
|
+
this.renderedDiff = result.fileDiff;
|
|
1283
1602
|
};
|
|
1284
1603
|
this.cleanupErrorWrapper();
|
|
1285
1604
|
applyChunk(prependResult, "afterbegin");
|
|
@@ -1302,8 +1621,9 @@ var FileDiff = class {
|
|
|
1302
1621
|
} else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition");
|
|
1303
1622
|
}
|
|
1304
1623
|
refreshSplitDiffView() {
|
|
1305
|
-
|
|
1306
|
-
|
|
1624
|
+
const fileDiff = this.getLatestDiff();
|
|
1625
|
+
if (this.options.diffStyle !== "split" || fileDiff == null) return;
|
|
1626
|
+
const hunksResult = this.hunksRenderer.renderDiff(fileDiff, this.renderRange);
|
|
1307
1627
|
if (hunksResult == null) return;
|
|
1308
1628
|
const columns = this.getCodeColumns("split", this.codeUnified, this.codeDeletions, this.codeAdditions);
|
|
1309
1629
|
if (!Array.isArray(columns)) return;
|
|
@@ -1320,10 +1640,12 @@ var FileDiff = class {
|
|
|
1320
1640
|
};
|
|
1321
1641
|
applyLineType("deletions", columns[0]);
|
|
1322
1642
|
applyLineType("additions", columns[1]);
|
|
1643
|
+
this.renderedDiff = hunksResult.fileDiff;
|
|
1323
1644
|
}
|
|
1324
1645
|
refreshUnifiedDiffView() {
|
|
1325
|
-
|
|
1326
|
-
|
|
1646
|
+
const fileDiff = this.getLatestDiff();
|
|
1647
|
+
if (this.options.diffStyle !== "unified" || fileDiff == null) return;
|
|
1648
|
+
const hunksResult = this.hunksRenderer.renderDiff(fileDiff, this.renderRange);
|
|
1327
1649
|
if (hunksResult == null) return;
|
|
1328
1650
|
const columns = this.getCodeColumns("unified", this.codeUnified, this.codeDeletions, this.codeAdditions);
|
|
1329
1651
|
if (columns == null || Array.isArray(columns)) return;
|
|
@@ -1336,6 +1658,7 @@ var FileDiff = class {
|
|
|
1336
1658
|
this.applyRowSpan("unified", columns, hunksResult.rowCount);
|
|
1337
1659
|
this.lastRowCount = hunksResult.rowCount;
|
|
1338
1660
|
}
|
|
1661
|
+
this.renderedDiff = hunksResult.fileDiff;
|
|
1339
1662
|
};
|
|
1340
1663
|
if (this.shouldGuardRebuildScroll()) guardWebKitScrollDuringRebuild(this.pre, applyColumns);
|
|
1341
1664
|
else applyColumns();
|
|
@@ -1626,6 +1949,13 @@ var FileDiff = class {
|
|
|
1626
1949
|
this.errorWrapper = void 0;
|
|
1627
1950
|
}
|
|
1628
1951
|
};
|
|
1952
|
+
function getAdditionFile(fileDiff) {
|
|
1953
|
+
return {
|
|
1954
|
+
name: fileDiff.name,
|
|
1955
|
+
lang: fileDiff.lang,
|
|
1956
|
+
contents: fileDiff.additionLines.join("")
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1629
1959
|
function areOptionalFilesEqual(fileA, fileB) {
|
|
1630
1960
|
if (fileA == null || fileB == null) return fileA == null && fileB == null;
|
|
1631
1961
|
return areFilesEqual(fileA, fileB);
|