@pierre/diffs 1.2.12 → 1.3.0-beta.10
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 +91 -6
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +300 -38
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +14 -3
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +98 -12
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +68 -19
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +363 -25
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +2 -1
- package/dist/components/FileStream.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 +4 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +59 -47
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +27 -5
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +262 -56
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +4 -1
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js +21 -4
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/constants.d.ts +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/command.d.ts +7 -0
- package/dist/editor/command.d.ts.map +1 -0
- package/dist/editor/command.js +54 -0
- package/dist/editor/command.js.map +1 -0
- package/dist/editor/editStack.d.ts +71 -0
- package/dist/editor/editStack.d.ts.map +1 -0
- package/dist/editor/editStack.js +218 -0
- package/dist/editor/editStack.js.map +1 -0
- package/dist/editor/editor.d.ts +105 -0
- package/dist/editor/editor.d.ts.map +1 -0
- package/dist/editor/editor.js +2545 -0
- package/dist/editor/editor.js.map +1 -0
- package/dist/editor/editor2.js +6 -0
- package/dist/editor/editor2.js.map +1 -0
- package/dist/editor/index.d.ts +5 -0
- package/dist/editor/index.js +3 -0
- package/dist/editor/languages.d.ts +26 -0
- package/dist/editor/languages.d.ts.map +1 -0
- package/dist/editor/languages.js +363 -0
- package/dist/editor/languages.js.map +1 -0
- package/dist/editor/lineAnnotations.d.ts +9 -0
- package/dist/editor/lineAnnotations.d.ts.map +1 -0
- package/dist/editor/lineAnnotations.js +212 -0
- package/dist/editor/lineAnnotations.js.map +1 -0
- package/dist/editor/marker.d.ts +38 -0
- package/dist/editor/marker.d.ts.map +1 -0
- package/dist/editor/marker.js +245 -0
- package/dist/editor/marker.js.map +1 -0
- package/dist/editor/matchBrackets.d.ts +9 -0
- package/dist/editor/matchBrackets.d.ts.map +1 -0
- package/dist/editor/matchBrackets.js +138 -0
- package/dist/editor/matchBrackets.js.map +1 -0
- package/dist/editor/pieceTable.d.ts +41 -0
- package/dist/editor/pieceTable.d.ts.map +1 -0
- package/dist/editor/pieceTable.js +671 -0
- package/dist/editor/pieceTable.js.map +1 -0
- package/dist/editor/platform.d.ts +19 -0
- package/dist/editor/platform.d.ts.map +1 -0
- package/dist/editor/platform.js +57 -0
- package/dist/editor/platform.js.map +1 -0
- package/dist/editor/popover.d.ts +65 -0
- package/dist/editor/popover.d.ts.map +1 -0
- package/dist/editor/popover.js +187 -0
- package/dist/editor/popover.js.map +1 -0
- package/dist/editor/searchPanel.d.ts +40 -0
- package/dist/editor/searchPanel.d.ts.map +1 -0
- package/dist/editor/searchPanel.js +318 -0
- package/dist/editor/searchPanel.js.map +1 -0
- package/dist/editor/selection.d.ts +211 -0
- package/dist/editor/selection.d.ts.map +1 -0
- package/dist/editor/selection.js +1626 -0
- package/dist/editor/selection.js.map +1 -0
- package/dist/editor/selectionAction.d.ts +46 -0
- package/dist/editor/selectionAction.d.ts.map +1 -0
- package/dist/editor/selectionAction.js +64 -0
- package/dist/editor/selectionAction.js.map +1 -0
- package/dist/editor/sprite.d.ts +8 -0
- package/dist/editor/sprite.d.ts.map +1 -0
- package/dist/editor/sprite.js +45 -0
- package/dist/editor/sprite.js.map +1 -0
- package/dist/editor/stateStorage.d.ts +15 -0
- package/dist/editor/stateStorage.d.ts.map +1 -0
- package/dist/editor/stateStorage.js +65 -0
- package/dist/editor/stateStorage.js.map +1 -0
- package/dist/editor/textDocument.d.ts +77 -0
- package/dist/editor/textDocument.d.ts.map +1 -0
- package/dist/editor/textDocument.js +271 -0
- package/dist/editor/textDocument.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +61 -0
- package/dist/editor/textMeasure.d.ts.map +1 -0
- package/dist/editor/textMeasure.js +209 -0
- package/dist/editor/textMeasure.js.map +1 -0
- package/dist/editor/tokenizer.d.ts +41 -0
- package/dist/editor/tokenizer.d.ts.map +1 -0
- package/dist/editor/tokenizer.js +513 -0
- package/dist/editor/tokenizer.js.map +1 -0
- package/dist/editor/utils.d.ts +21 -0
- package/dist/editor/utils.d.ts.map +1 -0
- package/dist/editor/utils.js +68 -0
- package/dist/editor/utils.js.map +1 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +12 -10
- package/dist/managers/InteractionManager.d.ts +7 -0
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +22 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/ResizeManager.d.ts +10 -2
- package/dist/managers/ResizeManager.d.ts.map +1 -1
- package/dist/managers/ResizeManager.js +33 -13
- package/dist/managers/ResizeManager.js.map +1 -1
- package/dist/managers/UniversalRenderingManager.d.ts +2 -1
- package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
- package/dist/managers/UniversalRenderingManager.js +6 -1
- package/dist/managers/UniversalRenderingManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +26 -1
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +82 -19
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +15 -0
- package/dist/react/EditContext.d.ts.map +1 -0
- package/dist/react/EditContext.js +23 -0
- package/dist/react/EditContext.js.map +1 -0
- package/dist/react/File.d.ts +3 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +4 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +4 -1
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +4 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +7 -5
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +4 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +4 -1
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +4 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +1 -0
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js +2 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +2 -1
- package/dist/react/types.d.ts +3 -0
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +2 -0
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +16 -8
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +2 -0
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +16 -8
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +3 -1
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +30 -6
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +4 -1
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +30 -5
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +28 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +244 -22
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +8 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +155 -45
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +11 -10
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +15 -7
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +282 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/applyLineTextWithNewline.d.ts +5 -0
- package/dist/utils/applyLineTextWithNewline.d.ts.map +1 -0
- package/dist/utils/applyLineTextWithNewline.js +11 -0
- package/dist/utils/applyLineTextWithNewline.js.map +1 -0
- package/dist/utils/areHunkDataEqual.js +1 -1
- package/dist/utils/areHunkDataEqual.js.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts +2 -2
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js +5 -0
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/awaitWithTimeout.d.ts +5 -0
- package/dist/utils/awaitWithTimeout.d.ts.map +1 -0
- package/dist/utils/awaitWithTimeout.js +15 -0
- package/dist/utils/awaitWithTimeout.js.map +1 -0
- package/dist/utils/cleanLastNewline.js +6 -1
- package/dist/utils/cleanLastNewline.js.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +7 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.js +16 -0
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -0
- package/dist/utils/computeEstimatedDiffHeights.d.ts +3 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +8 -1
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/computeFileOffsets.d.ts +21 -0
- package/dist/utils/computeFileOffsets.d.ts.map +1 -0
- package/dist/utils/computeFileOffsets.js +51 -0
- package/dist/utils/computeFileOffsets.js.map +1 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts +5 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts.map +1 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.js +19 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.js.map +1 -0
- package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
- package/dist/utils/createFileHeaderElement.js +5 -1
- package/dist/utils/createFileHeaderElement.js.map +1 -1
- package/dist/utils/createTransformerWithState.js +9 -0
- package/dist/utils/createTransformerWithState.js.map +1 -1
- package/dist/utils/editSessionHunks.d.ts +84 -0
- package/dist/utils/editSessionHunks.d.ts.map +1 -0
- package/dist/utils/editSessionHunks.js +366 -0
- package/dist/utils/editSessionHunks.js.map +1 -0
- package/dist/utils/getDiffFileInput.d.ts +14 -0
- package/dist/utils/getDiffFileInput.d.ts.map +1 -0
- package/dist/utils/getDiffFileInput.js +24 -0
- package/dist/utils/getDiffFileInput.js.map +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js +2 -0
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts +10 -0
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -0
- package/dist/utils/hydratePartialDiff.js +140 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -0
- package/dist/utils/iterateOverDiff.js +3 -3
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +1 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +26 -5
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +2 -0
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/realignChangeContent.d.ts +28 -0
- package/dist/utils/realignChangeContent.d.ts.map +1 -0
- package/dist/utils/realignChangeContent.js +142 -0
- package/dist/utils/realignChangeContent.js.map +1 -0
- package/dist/utils/renderDiffWithHighlighter.js +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +5 -14
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +24 -0
- package/dist/utils/updateDiffHunks.d.ts.map +1 -0
- package/dist/utils/updateDiffHunks.js +235 -0
- package/dist/utils/updateDiffHunks.js.map +1 -0
- package/dist/utils/virtualDiffLayout.d.ts +40 -1
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +96 -1
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +7 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +83 -18
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/index.d.ts +2 -2
- package/dist/worker/types.d.ts +11 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +46 -66
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +46 -66
- package/dist/worker/worker.js.map +1 -1
- package/package.json +12 -5
- package/dist/utils/iterateOverFile.d.ts +0 -50
- package/dist/utils/iterateOverFile.d.ts.map +0 -1
- package/dist/utils/iterateOverFile.js +0 -49
- package/dist/utils/iterateOverFile.js.map +0 -1
|
@@ -1,9 +1,14 @@
|
|
|
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 { preserveTrailingEditorBlankLine, recomputeDiffHunksForEdit, recomputeEmptyDocumentDiff, recomputeTopAlignedAdditionDiff, shouldTopAlignAdditionRecompute, updateDiffHunks } from "../utils/updateDiffHunks.js";
|
|
5
|
+
import { applySessionChangedLines, applySessionEditWindow, findChangedLineWindow, normalizeEditorLines, remapExpandedHunksForRegionChange } from "../utils/editSessionHunks.js";
|
|
2
6
|
import { getFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
|
|
3
7
|
import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
|
|
4
8
|
import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
|
|
5
9
|
import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
|
|
6
10
|
import { areThemesAttached } from "../highlighter/themes/areThemesAttached.js";
|
|
11
|
+
import { applyLineTextWithNewline } from "../utils/applyLineTextWithNewline.js";
|
|
7
12
|
import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
|
|
8
13
|
import { createAnnotationElement } from "../utils/createAnnotationElement.js";
|
|
9
14
|
import { createContentColumn } from "../utils/createContentColumn.js";
|
|
@@ -14,7 +19,6 @@ import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
|
|
|
14
19
|
import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
15
20
|
import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
|
|
16
21
|
import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
|
|
17
|
-
import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
|
|
18
22
|
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
19
23
|
import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
|
|
20
24
|
import { createEmptyRowBuffer } from "../utils/createEmptyRowBuffer.js";
|
|
@@ -40,6 +44,8 @@ var DiffHunksRenderer = class {
|
|
|
40
44
|
additionAnnotations = {};
|
|
41
45
|
computedLang = "text";
|
|
42
46
|
renderCache;
|
|
47
|
+
editSessionActive = false;
|
|
48
|
+
editSessionLines;
|
|
43
49
|
constructor(options = { theme: DEFAULT_THEMES }, onRenderUpdate, workerManager) {
|
|
44
50
|
this.options = options;
|
|
45
51
|
this.onRenderUpdate = onRenderUpdate;
|
|
@@ -59,9 +65,31 @@ var DiffHunksRenderer = class {
|
|
|
59
65
|
this.additionAnnotations = {};
|
|
60
66
|
this.deletionAnnotations = {};
|
|
61
67
|
this.workerManager?.cleanUpTasks(this);
|
|
68
|
+
this.endEditSession();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Enter edit-session mode: hunk updates preserve the current region
|
|
72
|
+
* skeleton instead of recomputing hunks. Called on every editor attach,
|
|
73
|
+
* including a re-attach after recycle, which losslessly re-seeds the pass
|
|
74
|
+
* snapshot because both hunk-update paths keep `diff.additionLines`
|
|
75
|
+
* current.
|
|
76
|
+
*/
|
|
77
|
+
beginEditSession(diff) {
|
|
78
|
+
this.editSessionActive = true;
|
|
79
|
+
this.editSessionLines = diff != null ? normalizeEditorLines(diff.additionLines).slice() : void 0;
|
|
80
|
+
}
|
|
81
|
+
/** Leave edit-session mode. The exit recompute is the host's concern. */
|
|
82
|
+
endEditSession() {
|
|
83
|
+
this.editSessionActive = false;
|
|
84
|
+
this.editSessionLines = void 0;
|
|
85
|
+
}
|
|
86
|
+
get diffCache() {
|
|
87
|
+
return this.renderCache?.diff ?? this.diff;
|
|
62
88
|
}
|
|
63
89
|
clearRenderCache() {
|
|
90
|
+
const renderCache = this.renderCache;
|
|
64
91
|
this.renderCache = void 0;
|
|
92
|
+
if (renderCache != null && renderCache.isDirty === true && renderCache.diff.cacheKey != null) this.workerManager?.evictDiffFromCache(renderCache.diff.cacheKey);
|
|
65
93
|
}
|
|
66
94
|
setOptions(options) {
|
|
67
95
|
this.options = options;
|
|
@@ -88,6 +116,10 @@ var DiffHunksRenderer = class {
|
|
|
88
116
|
getExpandedHunksMap() {
|
|
89
117
|
return this.expandedHunks;
|
|
90
118
|
}
|
|
119
|
+
/** Replace the whole expansion map (session-exit expansion remapping). */
|
|
120
|
+
setExpandedHunksMap(expandedHunks) {
|
|
121
|
+
this.expandedHunks = expandedHunks;
|
|
122
|
+
}
|
|
91
123
|
setLineAnnotations(lineAnnotations) {
|
|
92
124
|
this.additionAnnotations = {};
|
|
93
125
|
this.deletionAnnotations = {};
|
|
@@ -103,12 +135,140 @@ var DiffHunksRenderer = class {
|
|
|
103
135
|
arr.push(annotation);
|
|
104
136
|
}
|
|
105
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns true when a session-mode pass changed the region skeleton itself
|
|
140
|
+
* (a gap edit synthesized or merged regions), which changes the rendered
|
|
141
|
+
* row set without a line-count change — the host must escalate to a full
|
|
142
|
+
* re-render instead of its cheap refresh path.
|
|
143
|
+
*/
|
|
144
|
+
updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
|
|
145
|
+
if (this.renderCache == null) return false;
|
|
146
|
+
const { result, diff } = this.renderCache;
|
|
147
|
+
if (result == null) return false;
|
|
148
|
+
if (diff.isPartial) throw new Error("Could not update render cache for partial diff");
|
|
149
|
+
const hastLines = result.code.additionLines;
|
|
150
|
+
const changedAdditionLines = [];
|
|
151
|
+
for (const [line, tokens] of dirtyLines) {
|
|
152
|
+
const prevProps = hastLines[line]?.properties ?? {};
|
|
153
|
+
const lineText = tokens.map((a) => a[2]).join("");
|
|
154
|
+
const canSyncDiffLine = line < diff.additionLines.length;
|
|
155
|
+
const prevLine = canSyncDiffLine ? diff.additionLines[line] ?? "" : "";
|
|
156
|
+
const prevText = cleanLastNewline(prevLine);
|
|
157
|
+
if (canSyncDiffLine) {
|
|
158
|
+
diff.additionLines[line] = applyLineTextWithNewline(prevLine, lineText);
|
|
159
|
+
if (prevText !== lineText) changedAdditionLines.push(line);
|
|
160
|
+
}
|
|
161
|
+
hastLines[line] = {
|
|
162
|
+
type: "element",
|
|
163
|
+
tagName: "div",
|
|
164
|
+
properties: {
|
|
165
|
+
"data-line": prevProps["data-line"] ?? line + 1,
|
|
166
|
+
"data-line-index": prevProps["data-line-index"] ?? line,
|
|
167
|
+
"data-line-type": prevProps["data-line-type"] ?? "context"
|
|
168
|
+
},
|
|
169
|
+
children: tokens.map(([char, fg, text]) => {
|
|
170
|
+
if (char === 0 && fg === "") {
|
|
171
|
+
if (text === "") return {
|
|
172
|
+
type: "element",
|
|
173
|
+
tagName: "br",
|
|
174
|
+
properties: {},
|
|
175
|
+
children: []
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
type: "text",
|
|
179
|
+
value: text
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
type: "element",
|
|
184
|
+
tagName: "span",
|
|
185
|
+
properties: {
|
|
186
|
+
"data-char": char,
|
|
187
|
+
style: `color:${fg};`
|
|
188
|
+
},
|
|
189
|
+
children: [{
|
|
190
|
+
type: "text",
|
|
191
|
+
value: text
|
|
192
|
+
}]
|
|
193
|
+
};
|
|
194
|
+
})
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
let regionsChanged = false;
|
|
198
|
+
if (changedAdditionLines.length > 0) if (this.editSessionActive && !diff.isPartial) {
|
|
199
|
+
if (!lineCountChangeInFlight) {
|
|
200
|
+
const changes = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions);
|
|
201
|
+
this.applyExpansionRemaps(changes);
|
|
202
|
+
regionsChanged = changes.length > 0;
|
|
203
|
+
this.editSessionLines = normalizeEditorLines(diff.additionLines).slice();
|
|
204
|
+
}
|
|
205
|
+
} else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
206
|
+
result.baseThemeType = themeType;
|
|
207
|
+
this.renderCache.isDirty = true;
|
|
208
|
+
return regionsChanged;
|
|
209
|
+
}
|
|
210
|
+
applyExpansionRemaps(changes) {
|
|
211
|
+
for (const change of changes) this.expandedHunks = remapExpandedHunksForRegionChange(this.expandedHunks, change);
|
|
212
|
+
}
|
|
213
|
+
applyDocumentChange(textDocument) {
|
|
214
|
+
if (this.renderCache == null) return;
|
|
215
|
+
const { diff, result } = this.renderCache;
|
|
216
|
+
if (result == null) return;
|
|
217
|
+
diff.additionLines = getEditorDocumentLines(textDocument, diff.additionLines);
|
|
218
|
+
const newLength = diff.additionLines.length;
|
|
219
|
+
const additionHastLines = result.code.additionLines;
|
|
220
|
+
const prevLen = additionHastLines.length;
|
|
221
|
+
if (newLength < prevLen) additionHastLines.length = newLength;
|
|
222
|
+
for (let i = prevLen; i < newLength; i++) additionHastLines[i] ??= createPlainAdditionLineElement(i, textDocument);
|
|
223
|
+
if (!diff.isPartial) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
224
|
+
Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
225
|
+
additionHastLines[0] = createPlainAdditionLineElement(0, textDocument);
|
|
226
|
+
this.markEditSessionPass(diff);
|
|
227
|
+
} else if (this.editSessionActive) this.applySessionDocumentChange(diff);
|
|
228
|
+
else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
|
|
229
|
+
this.renderCache.isDirty = true;
|
|
230
|
+
}
|
|
231
|
+
applySessionDocumentChange(diff) {
|
|
232
|
+
const { parseDiffOptions } = this.options;
|
|
233
|
+
const rawLines = diff.additionLines;
|
|
234
|
+
if (shouldTopAlignAdditionRecompute(diff, rawLines)) {
|
|
235
|
+
Object.assign(diff, recomputeTopAlignedAdditionDiff(diff, rawLines, parseDiffOptions));
|
|
236
|
+
this.markEditSessionPass(diff);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const previousLines = this.editSessionLines;
|
|
240
|
+
const nextLines = normalizeEditorLines(rawLines);
|
|
241
|
+
if (previousLines == null) {
|
|
242
|
+
Object.assign(diff, recomputeDiffHunksForEdit(diff, parseDiffOptions));
|
|
243
|
+
this.markEditSessionPass(diff);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
diff.additionLines = nextLines;
|
|
247
|
+
const window = findChangedLineWindow(previousLines, nextLines);
|
|
248
|
+
if (window != null) {
|
|
249
|
+
const change = applySessionEditWindow(diff, window, parseDiffOptions);
|
|
250
|
+
if (change != null) this.applyExpansionRemaps([change]);
|
|
251
|
+
}
|
|
252
|
+
preserveTrailingEditorBlankLine(diff, rawLines);
|
|
253
|
+
this.editSessionLines = nextLines.slice();
|
|
254
|
+
}
|
|
255
|
+
markEditSessionPass(diff) {
|
|
256
|
+
if (!this.editSessionActive) return;
|
|
257
|
+
diff.editSessionDirty = true;
|
|
258
|
+
this.editSessionLines = normalizeEditorLines(diff.additionLines).slice();
|
|
259
|
+
}
|
|
106
260
|
getUnifiedLineDecoration({ lineType }) {
|
|
107
|
-
return {
|
|
261
|
+
return {
|
|
262
|
+
gutterLineType: lineType,
|
|
263
|
+
contentProperties: { "data-line-type": lineType }
|
|
264
|
+
};
|
|
108
265
|
}
|
|
109
266
|
getSplitLineDecoration({ side, type }) {
|
|
110
|
-
|
|
111
|
-
return {
|
|
267
|
+
const lineType = type === "change" ? side === "deletions" ? "change-deletion" : "change-addition" : type;
|
|
268
|
+
return {
|
|
269
|
+
gutterLineType: lineType,
|
|
270
|
+
contentProperties: { "data-line-type": lineType }
|
|
271
|
+
};
|
|
112
272
|
}
|
|
113
273
|
createAnnotationElement = (span) => {
|
|
114
274
|
return createAnnotationElement(span);
|
|
@@ -193,7 +353,7 @@ var DiffHunksRenderer = class {
|
|
|
193
353
|
}
|
|
194
354
|
renderDiff(diff = this.renderCache?.diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
195
355
|
if (diff == null) return;
|
|
196
|
-
const { expandUnchanged
|
|
356
|
+
const { expandUnchanged, collapsedContextThreshold } = this.getOptionsWithDefaults();
|
|
197
357
|
let { options, forceHighlight } = this.getRenderOptions(diff);
|
|
198
358
|
const cache = this.getMatchingWorkerResultCache(diff, options);
|
|
199
359
|
if (cache != null && !this.hasHighlightedRenderCache(diff, options)) {
|
|
@@ -313,8 +473,11 @@ var DiffHunksRenderer = class {
|
|
|
313
473
|
}
|
|
314
474
|
processDiffResult(fileDiff, renderRange, { code, themeStyles, baseThemeType }) {
|
|
315
475
|
const { diffStyle, disableFileHeader, expandUnchanged, expansionLineCount, collapsedContextThreshold, hunkSeparators } = this.getOptionsWithDefaults();
|
|
476
|
+
const isRenderCacheDirty = this.renderCache?.isDirty ?? false;
|
|
316
477
|
this.diff = fileDiff;
|
|
317
478
|
const unified = diffStyle === "unified";
|
|
479
|
+
const canHydrateContext = canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null);
|
|
480
|
+
const isExpandableDiff = !fileDiff.isPartial || canHydrateContext;
|
|
318
481
|
let additionsContentAST = [];
|
|
319
482
|
let deletionsContentAST = [];
|
|
320
483
|
let unifiedContentAST = [];
|
|
@@ -406,7 +569,7 @@ var DiffHunksRenderer = class {
|
|
|
406
569
|
hunkSpecs: hunk?.hunkSpecs,
|
|
407
570
|
isFirstHunk: hunkIndex === 0,
|
|
408
571
|
isLastHunk: false,
|
|
409
|
-
isExpandable:
|
|
572
|
+
isExpandable: isExpandableDiff
|
|
410
573
|
});
|
|
411
574
|
const lineIndex = diffStyle === "unified" ? unifiedLineIndex : splitLineIndex;
|
|
412
575
|
const renderedLineContext = {
|
|
@@ -436,8 +599,14 @@ var DiffHunksRenderer = class {
|
|
|
436
599
|
deletionLineIndex: deletionLine?.lineIndex
|
|
437
600
|
});
|
|
438
601
|
pushGutterLineNumber("unified", lineDecoration.gutterLineType, additionLine != null ? additionLine.lineNumber : deletionLine.lineNumber, `${unifiedLineIndex},${splitLineIndex}`, lineDecoration.gutterProperties);
|
|
439
|
-
if (additionLineContent != null) additionLineContent = withContentProperties(additionLineContent, lineDecoration.contentProperties
|
|
440
|
-
|
|
602
|
+
if (additionLineContent != null) additionLineContent = withContentProperties(additionLineContent, lineDecoration.contentProperties, isRenderCacheDirty && additionLine != null ? {
|
|
603
|
+
"data-line": additionLine.lineNumber,
|
|
604
|
+
"data-line-index": `${unifiedLineIndex},${splitLineIndex}`
|
|
605
|
+
} : void 0);
|
|
606
|
+
else if (deletionLineContent != null) deletionLineContent = withContentProperties(deletionLineContent, lineDecoration.contentProperties, isRenderCacheDirty && deletionLine != null ? {
|
|
607
|
+
"data-line": deletionLine.lineNumber,
|
|
608
|
+
"data-line-index": `${unifiedLineIndex},${splitLineIndex}`
|
|
609
|
+
} : void 0);
|
|
441
610
|
pushLineWithAnnotation({
|
|
442
611
|
diffStyle: "unified",
|
|
443
612
|
type,
|
|
@@ -475,19 +644,25 @@ var DiffHunksRenderer = class {
|
|
|
475
644
|
}
|
|
476
645
|
})();
|
|
477
646
|
if (missingSide != null) {
|
|
478
|
-
if (pendingSplitContext.side != null && pendingSplitContext.side !== missingSide)
|
|
647
|
+
if (pendingSplitContext.side != null && pendingSplitContext.side !== missingSide) pendingSplitContext.flush();
|
|
479
648
|
pendingSplitContext.side = missingSide;
|
|
480
649
|
pendingSplitContext.increment();
|
|
481
|
-
}
|
|
650
|
+
} else if (type === "change") pendingSplitContext.flush();
|
|
482
651
|
const annotationSpans = this.getAnnotations("split", deletionLine?.lineNumber, additionLine?.lineNumber, hunkIndex, lineIndex);
|
|
483
652
|
if (annotationSpans != null && pendingSplitContext.size > 0) pendingSplitContext.flush();
|
|
484
653
|
if (deletionLine != null) {
|
|
485
|
-
const deletionLineDecorated = withContentProperties(deletionLineContent, deletionLineDecoration.contentProperties
|
|
654
|
+
const deletionLineDecorated = withContentProperties(deletionLineContent, deletionLineDecoration.contentProperties, isRenderCacheDirty ? {
|
|
655
|
+
"data-line": deletionLine.lineNumber,
|
|
656
|
+
"data-line-index": `${deletionLine.unifiedLineIndex},${splitLineIndex}`
|
|
657
|
+
} : void 0);
|
|
486
658
|
pushGutterLineNumber("deletions", deletionLineDecoration.gutterLineType, deletionLine.lineNumber, `${deletionLine.unifiedLineIndex},${splitLineIndex}`, deletionLineDecoration.gutterProperties);
|
|
487
659
|
if (deletionLineDecorated != null) deletionLineContent = deletionLineDecorated;
|
|
488
660
|
}
|
|
489
661
|
if (additionLine != null) {
|
|
490
|
-
const additionLineDecorated = withContentProperties(additionLineContent, additionLineDecoration.contentProperties
|
|
662
|
+
const additionLineDecorated = withContentProperties(additionLineContent, additionLineDecoration.contentProperties, isRenderCacheDirty ? {
|
|
663
|
+
"data-line": additionLine.lineNumber,
|
|
664
|
+
"data-line-index": `${additionLine.unifiedLineIndex},${splitLineIndex}`
|
|
665
|
+
} : void 0);
|
|
491
666
|
pushGutterLineNumber("additions", additionLineDecoration.gutterLineType, additionLine.lineNumber, `${additionLine.unifiedLineIndex},${splitLineIndex}`, additionLineDecoration.gutterProperties);
|
|
492
667
|
if (additionLineDecorated != null) additionLineContent = additionLineDecorated;
|
|
493
668
|
}
|
|
@@ -503,6 +678,7 @@ var DiffHunksRenderer = class {
|
|
|
503
678
|
if (injectedRows?.after != null) pushSplitInjectedRows(injectedRows.after, context, pendingSplitContext);
|
|
504
679
|
}
|
|
505
680
|
const isFinalSplitHunkRow = diffStyle === "split" && hunk != null && splitLineIndex === hunk.splitLineStart + hunk.splitLineCount - 1;
|
|
681
|
+
const isFinalHunkRow = hunkIndex === fileDiff.hunks.length - 1 && hunk != null && (diffStyle === "split" ? splitLineIndex === hunk.splitLineStart + hunk.splitLineCount - 1 : unifiedLineIndex === hunk.unifiedLineStart + hunk.unifiedLineCount - 1);
|
|
506
682
|
const splitNoEOFCRDeletion = isFinalSplitHunkRow ? hunk.noEOFCRDeletions : false;
|
|
507
683
|
const splitNoEOFCRAddition = isFinalSplitHunkRow ? hunk.noEOFCRAdditions : false;
|
|
508
684
|
const noEOFCRDeletion = (deletionLine?.noEOFCR ?? false) || splitNoEOFCRDeletion;
|
|
@@ -539,14 +715,14 @@ var DiffHunksRenderer = class {
|
|
|
539
715
|
}
|
|
540
716
|
context.incrementRowCount(1);
|
|
541
717
|
}
|
|
542
|
-
if (
|
|
718
|
+
if (hunkSeparators !== "simple" && hunkSeparators !== "metadata" && (collapsedAfter > 0 || isFinalHunkRow && canHydrateContext)) pushSeparators({
|
|
543
719
|
hunkIndex: type === "context-expanded" ? hunkIndex : hunkIndex + 1,
|
|
544
|
-
collapsedLines: collapsedAfter,
|
|
720
|
+
collapsedLines: isFinalHunkRow && canHydrateContext ? "unknown" : collapsedAfter,
|
|
545
721
|
rangeSize: trailingRangeSize,
|
|
546
722
|
hunkSpecs: void 0,
|
|
547
723
|
isFirstHunk: false,
|
|
548
724
|
isLastHunk: true,
|
|
549
|
-
isExpandable:
|
|
725
|
+
isExpandable: isExpandableDiff
|
|
550
726
|
});
|
|
551
727
|
context.incrementRowCount(1);
|
|
552
728
|
}
|
|
@@ -786,7 +962,7 @@ function pushLineWithAnnotation({ diffStyle, type, deletionLine, additionLine, u
|
|
|
786
962
|
if (hasAnnotationRow) context.incrementRowCount(1);
|
|
787
963
|
}
|
|
788
964
|
function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs, isFirstHunk, isLastHunk, isExpandable }, context) {
|
|
789
|
-
if (collapsedLines <= 0) return;
|
|
965
|
+
if (typeof collapsedLines === "number" && collapsedLines <= 0) return;
|
|
790
966
|
const linesAST = type === "unified" ? context.unifiedContentAST : type === "deletions" ? context.deletionsContentAST : context.additionsContentAST;
|
|
791
967
|
if (context.hunkSeparators === "metadata") {
|
|
792
968
|
if (hunkSpecs != null) {
|
|
@@ -825,9 +1001,10 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
825
1001
|
const slotName = getHunkSeparatorSlotName(type, hunkIndex);
|
|
826
1002
|
const chunked = rangeSize > context.expansionLineCount;
|
|
827
1003
|
const expandIndex = isExpandable ? hunkIndex : void 0;
|
|
1004
|
+
const content = typeof collapsedLines === "number" ? getModifiedLinesString(collapsedLines) : "More unchanged context may be available";
|
|
828
1005
|
context.pushToGutter(type, createSeparator({
|
|
829
1006
|
type: context.hunkSeparators,
|
|
830
|
-
content
|
|
1007
|
+
content,
|
|
831
1008
|
expandIndex,
|
|
832
1009
|
chunked,
|
|
833
1010
|
slotName,
|
|
@@ -836,7 +1013,7 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
836
1013
|
}));
|
|
837
1014
|
linesAST.push(createSeparator({
|
|
838
1015
|
type: context.hunkSeparators,
|
|
839
|
-
content
|
|
1016
|
+
content,
|
|
840
1017
|
expandIndex,
|
|
841
1018
|
chunked,
|
|
842
1019
|
slotName,
|
|
@@ -847,7 +1024,8 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
847
1024
|
context.hunkData.push({
|
|
848
1025
|
slotName,
|
|
849
1026
|
hunkIndex,
|
|
850
|
-
lines: collapsedLines,
|
|
1027
|
+
lines: typeof collapsedLines === "number" ? collapsedLines : 0,
|
|
1028
|
+
lineCountKnown: typeof collapsedLines === "number",
|
|
851
1029
|
type,
|
|
852
1030
|
expandable: isExpandable ? {
|
|
853
1031
|
up: !isFirstHunk,
|
|
@@ -856,19 +1034,63 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
856
1034
|
} : void 0
|
|
857
1035
|
});
|
|
858
1036
|
}
|
|
859
|
-
function withContentProperties(lineNode, contentProperties) {
|
|
860
|
-
if (lineNode == null || lineNode.type !== "element" || contentProperties == null) return lineNode;
|
|
1037
|
+
function withContentProperties(lineNode, contentProperties, extendProperties) {
|
|
1038
|
+
if (lineNode == null || lineNode.type !== "element" || contentProperties == null && extendProperties == null) return lineNode;
|
|
861
1039
|
return {
|
|
862
1040
|
...lineNode,
|
|
863
1041
|
properties: {
|
|
864
1042
|
...lineNode.properties,
|
|
865
|
-
...contentProperties
|
|
1043
|
+
...contentProperties,
|
|
1044
|
+
...extendProperties
|
|
866
1045
|
}
|
|
867
1046
|
};
|
|
868
1047
|
}
|
|
1048
|
+
function createPlainAdditionLineElement(lineIndex, textDocument) {
|
|
1049
|
+
return {
|
|
1050
|
+
type: "element",
|
|
1051
|
+
tagName: "div",
|
|
1052
|
+
properties: {
|
|
1053
|
+
"data-line": lineIndex + 1,
|
|
1054
|
+
"data-line-index": `${lineIndex},${lineIndex}`,
|
|
1055
|
+
"data-line-type": "context"
|
|
1056
|
+
},
|
|
1057
|
+
children: [{
|
|
1058
|
+
type: "element",
|
|
1059
|
+
tagName: "span",
|
|
1060
|
+
properties: { "data-char": 0 },
|
|
1061
|
+
children: [{
|
|
1062
|
+
type: "text",
|
|
1063
|
+
value: textDocument.getLineText(lineIndex)
|
|
1064
|
+
}]
|
|
1065
|
+
}]
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
function getEditorDocumentLines(textDocument, previousLines) {
|
|
1069
|
+
const lines = [];
|
|
1070
|
+
const fallbackLineBreak = getFallbackLineBreak(previousLines);
|
|
1071
|
+
for (let line = 0; line < textDocument.lineCount; line++) {
|
|
1072
|
+
const lineText = textDocument.getLineText(line, true);
|
|
1073
|
+
lines.push(line < textDocument.lineCount - 1 && !hasLineBreakSuffix(lineText) ? lineText + fallbackLineBreak : lineText);
|
|
1074
|
+
}
|
|
1075
|
+
return lines;
|
|
1076
|
+
}
|
|
1077
|
+
function hasLineBreakSuffix(line) {
|
|
1078
|
+
return line.endsWith("\n") || line.endsWith("\r");
|
|
1079
|
+
}
|
|
1080
|
+
function getFallbackLineBreak(lines) {
|
|
1081
|
+
for (const line of lines) {
|
|
1082
|
+
if (line.endsWith("\r\n")) return "\r\n";
|
|
1083
|
+
if (line.endsWith("\n")) return "\n";
|
|
1084
|
+
if (line.endsWith("\r")) return "\r";
|
|
1085
|
+
}
|
|
1086
|
+
return "\n";
|
|
1087
|
+
}
|
|
869
1088
|
function isDiffMassive(diff, tokenizeMaxLength) {
|
|
870
1089
|
return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
|
|
871
1090
|
}
|
|
1091
|
+
function canHydrateCollapsedContext(fileDiff, hasFileLoader) {
|
|
1092
|
+
return fileDiff.isPartial && hasFileLoader && (fileDiff.type === "change" || fileDiff.type === "rename-changed");
|
|
1093
|
+
}
|
|
872
1094
|
//#endregion
|
|
873
1095
|
export { DiffHunksRenderer };
|
|
874
1096
|
|