@pierre/diffs 1.3.0-beta.2 → 1.3.0-beta.4

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.
Files changed (158) hide show
  1. package/dist/components/CodeView.d.ts +4 -0
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +38 -0
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +2 -2
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +13 -13
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +7 -4
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +57 -47
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  14. package/dist/components/UnresolvedFile.js +1 -1
  15. package/dist/components/VirtualizedFile.d.ts +1 -1
  16. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  17. package/dist/components/VirtualizedFile.js +13 -4
  18. package/dist/components/VirtualizedFile.js.map +1 -1
  19. package/dist/components/VirtualizedFileDiff.d.ts +2 -1
  20. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.js +36 -42
  22. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  23. package/dist/components/Virtualizer.js +5 -3
  24. package/dist/components/Virtualizer.js.map +1 -1
  25. package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
  26. package/dist/editor/editStack.d.ts +1 -1
  27. package/dist/editor/editor.d.ts +14 -6
  28. package/dist/editor/editor.d.ts.map +1 -1
  29. package/dist/editor/editor.js +745 -553
  30. package/dist/editor/editor.js.map +1 -1
  31. package/dist/editor/editor2.js +6 -0
  32. package/dist/editor/editor2.js.map +1 -0
  33. package/dist/editor/lineAnnotations.d.ts +2 -1
  34. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  35. package/dist/editor/lineAnnotations.js +111 -1
  36. package/dist/editor/lineAnnotations.js.map +1 -1
  37. package/dist/editor/marker.d.ts +33 -0
  38. package/dist/editor/marker.d.ts.map +1 -0
  39. package/dist/editor/marker.js +185 -0
  40. package/dist/editor/marker.js.map +1 -0
  41. package/dist/editor/pieceTable.d.ts +3 -3
  42. package/dist/editor/pieceTable.d.ts.map +1 -1
  43. package/dist/editor/pieceTable.js +44 -33
  44. package/dist/editor/pieceTable.js.map +1 -1
  45. package/dist/editor/searchPanel.d.ts +6 -7
  46. package/dist/editor/searchPanel.d.ts.map +1 -1
  47. package/dist/editor/searchPanel.js +103 -138
  48. package/dist/editor/searchPanel.js.map +1 -1
  49. package/dist/editor/selection.d.ts +19 -3
  50. package/dist/editor/selection.d.ts.map +1 -1
  51. package/dist/editor/selection.js +196 -39
  52. package/dist/editor/selection.js.map +1 -1
  53. package/dist/editor/{quickEdit.d.ts → selectionAction.d.ts} +8 -8
  54. package/dist/editor/selectionAction.d.ts.map +1 -0
  55. package/dist/editor/{quickEdit.js → selectionAction.js} +19 -21
  56. package/dist/editor/selectionAction.js.map +1 -0
  57. package/dist/editor/sprite.d.ts +8 -0
  58. package/dist/editor/sprite.d.ts.map +1 -0
  59. package/dist/editor/sprite.js +45 -0
  60. package/dist/editor/sprite.js.map +1 -0
  61. package/dist/editor/textDocument.d.ts +5 -5
  62. package/dist/editor/textDocument.d.ts.map +1 -1
  63. package/dist/editor/textDocument.js +9 -9
  64. package/dist/editor/textDocument.js.map +1 -1
  65. package/dist/editor/textMeasure.js +3 -3
  66. package/dist/editor/textMeasure.js.map +1 -1
  67. package/dist/editor/tokenzier.d.ts +6 -2
  68. package/dist/editor/tokenzier.d.ts.map +1 -1
  69. package/dist/editor/tokenzier.js +135 -85
  70. package/dist/editor/tokenzier.js.map +1 -1
  71. package/dist/editor/utils.d.ts +3 -1
  72. package/dist/editor/utils.d.ts.map +1 -1
  73. package/dist/editor/utils.js +16 -1
  74. package/dist/editor/utils.js.map +1 -1
  75. package/dist/highlighter/shared_highlighter.js +3 -29
  76. package/dist/highlighter/shared_highlighter.js.map +1 -1
  77. package/dist/highlighter/themes/attachResolvedThemes.js +4 -3
  78. package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
  79. package/dist/highlighter/themes/cleanUpResolvedThemes.js +3 -2
  80. package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
  81. package/dist/highlighter/themes/constants.d.ts +1 -7
  82. package/dist/highlighter/themes/constants.d.ts.map +1 -1
  83. package/dist/highlighter/themes/constants.js +1 -4
  84. package/dist/highlighter/themes/constants.js.map +1 -1
  85. package/dist/highlighter/themes/getResolvedOrResolveTheme.js +2 -2
  86. package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
  87. package/dist/highlighter/themes/getResolvedThemes.js +2 -8
  88. package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
  89. package/dist/highlighter/themes/hasResolvedThemes.js +2 -3
  90. package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
  91. package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +1 -1
  92. package/dist/highlighter/themes/registerCustomTheme.d.ts +5 -3
  93. package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
  94. package/dist/highlighter/themes/registerCustomTheme.js +15 -5
  95. package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
  96. package/dist/highlighter/themes/resolveTheme.js +6 -27
  97. package/dist/highlighter/themes/resolveTheme.js.map +1 -1
  98. package/dist/highlighter/themes/resolveThemes.js +5 -12
  99. package/dist/highlighter/themes/resolveThemes.js.map +1 -1
  100. package/dist/highlighter/themes/themeResolution.d.ts +8 -0
  101. package/dist/highlighter/themes/themeResolution.d.ts.map +1 -0
  102. package/dist/highlighter/themes/themeResolution.js +22 -0
  103. package/dist/highlighter/themes/themeResolution.js.map +1 -0
  104. package/dist/highlighter/themes/themeResolver.d.ts +8 -0
  105. package/dist/highlighter/themes/themeResolver.d.ts.map +1 -0
  106. package/dist/highlighter/themes/themeResolver.js +8 -0
  107. package/dist/highlighter/themes/themeResolver.js.map +1 -0
  108. package/dist/index.d.ts +4 -4
  109. package/dist/index.js +3 -3
  110. package/dist/react/index.d.ts +2 -2
  111. package/dist/react/jsx.d.ts.map +1 -1
  112. package/dist/react/utils/useFileDiffInstance.js +1 -0
  113. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  114. package/dist/renderers/DiffHunksRenderer.d.ts +4 -1
  115. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  116. package/dist/renderers/DiffHunksRenderer.js +139 -19
  117. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  118. package/dist/renderers/FileRenderer.d.ts +2 -2
  119. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  120. package/dist/renderers/FileRenderer.js +5 -5
  121. package/dist/renderers/FileRenderer.js.map +1 -1
  122. package/dist/ssr/index.d.ts +2 -2
  123. package/dist/style.js +1 -1
  124. package/dist/style.js.map +1 -1
  125. package/dist/types.d.ts +19 -16
  126. package/dist/types.d.ts.map +1 -1
  127. package/dist/utils/computeEstimatedDiffHeights.js +9 -20
  128. package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
  129. package/dist/utils/getHighlighterThemeStyles.js +16 -12
  130. package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
  131. package/dist/utils/iterateOverDiff.js +147 -182
  132. package/dist/utils/iterateOverDiff.js.map +1 -1
  133. package/dist/utils/parsePatchFiles.js +93 -4
  134. package/dist/utils/parsePatchFiles.js.map +1 -1
  135. package/dist/utils/updateDiffHunks.d.ts +13 -0
  136. package/dist/utils/updateDiffHunks.d.ts.map +1 -0
  137. package/dist/utils/updateDiffHunks.js +171 -0
  138. package/dist/utils/updateDiffHunks.js.map +1 -0
  139. package/dist/utils/virtualDiffLayout.d.ts +24 -2
  140. package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
  141. package/dist/utils/virtualDiffLayout.js +49 -1
  142. package/dist/utils/virtualDiffLayout.js.map +1 -1
  143. package/dist/worker/WorkerPoolManager.js +1 -1
  144. package/dist/worker/WorkerPoolManager.js.map +1 -1
  145. package/dist/worker/{wasm-D4DU5jgR.js → wasm-BaDzIkIn.js} +2 -2
  146. package/dist/worker/wasm-BaDzIkIn.js.map +1 -0
  147. package/dist/worker/worker-portable.js +1021 -314
  148. package/dist/worker/worker-portable.js.map +1 -1
  149. package/dist/worker/worker.js +202 -196
  150. package/dist/worker/worker.js.map +1 -1
  151. package/package.json +4 -2
  152. package/dist/editor/css.d.ts +0 -6
  153. package/dist/editor/css.d.ts.map +0 -1
  154. package/dist/editor/css.js +0 -218
  155. package/dist/editor/css.js.map +0 -1
  156. package/dist/editor/quickEdit.d.ts.map +0 -1
  157. package/dist/editor/quickEdit.js.map +0 -1
  158. package/dist/worker/wasm-D4DU5jgR.js.map +0 -1
@@ -0,0 +1,171 @@
1
+ import { hasTrailingContextMismatch } from "./virtualDiffLayout.js";
2
+ import { cleanLastNewline } from "./cleanLastNewline.js";
3
+ import { parseDiffFromFile } from "./parseDiffFromFile.js";
4
+
5
+ //#region src/utils/updateDiffHunks.ts
6
+ /** Rebuilds all hunk metadata from the current deletion/addition line arrays. */
7
+ function recomputeDiffHunks(diff, parseDiffOptions) {
8
+ const recomputed = parseDiffFromFile({
9
+ name: diff.prevName ?? diff.name,
10
+ contents: diff.deletionLines.join("")
11
+ }, {
12
+ name: diff.name,
13
+ contents: diff.additionLines.join(""),
14
+ lang: diff.lang
15
+ }, parseDiffOptions);
16
+ return {
17
+ hunks: recomputed.hunks,
18
+ splitLineCount: recomputed.splitLineCount,
19
+ unifiedLineCount: recomputed.unifiedLineCount,
20
+ additionLines: recomputed.additionLines,
21
+ deletionLines: recomputed.deletionLines,
22
+ type: recomputed.type
23
+ };
24
+ }
25
+ /** Updates hunk metadata after addition lines change; re-parses affected hunks only. */
26
+ function updateDiffHunks(diff, changedAdditionLineIndexes, parseDiffOptions) {
27
+ if (diff.isPartial) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
28
+ if (diff.deletionLines.length !== diff.additionLines.length) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
29
+ const changedLines = Array.from(changedAdditionLineIndexes);
30
+ if (changedLines.length === 0) return applyHunkUpdateResult(diff, {
31
+ hunks: diff.hunks,
32
+ splitLineCount: diff.splitLineCount,
33
+ unifiedLineCount: diff.unifiedLineCount,
34
+ type: diff.type
35
+ });
36
+ for (const line of changedLines) {
37
+ const additionLine = diff.additionLines[line];
38
+ const deletionLine = diff.deletionLines[line];
39
+ if (additionLine == null || deletionLine == null) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
40
+ if (cleanLastNewline(additionLine) === cleanLastNewline(deletionLine)) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
41
+ }
42
+ const affectedHunkIndexes = getAffectedHunkIndexes(diff, changedLines);
43
+ if (affectedHunkIndexes.size === 0) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
44
+ for (const hunkIndex of affectedHunkIndexes) if (!reparseHunkRegion(diff, hunkIndex, parseDiffOptions)) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
45
+ recomputeDiffRenderLineCounts(diff);
46
+ if (hasTrailingContextMismatch(diff)) return applyHunkUpdateResult(diff, recomputeDiffHunks(diff, parseDiffOptions));
47
+ return applyHunkUpdateResult(diff, {
48
+ hunks: diff.hunks,
49
+ splitLineCount: diff.splitLineCount,
50
+ unifiedLineCount: diff.unifiedLineCount,
51
+ type: diff.type
52
+ });
53
+ }
54
+ function applyHunkUpdateResult(diff, result) {
55
+ Object.assign(diff, result);
56
+ return result;
57
+ }
58
+ function getAffectedHunkIndexes(diff, changedAdditionLineIndexes) {
59
+ const indexes = /* @__PURE__ */ new Set();
60
+ for (const line of changedAdditionLineIndexes) {
61
+ const hunkIndex = findHunkIndexForAdditionLine(diff, line);
62
+ if (hunkIndex == null) return /* @__PURE__ */ new Set();
63
+ indexes.add(hunkIndex);
64
+ }
65
+ return indexes;
66
+ }
67
+ function findHunkIndexForAdditionLine(diff, line) {
68
+ for (const [hunkIndex, hunk] of diff.hunks.entries()) {
69
+ const end = hunk.additionLineIndex + hunk.additionCount;
70
+ if (line >= hunk.additionLineIndex && line < end) return hunkIndex;
71
+ }
72
+ }
73
+ function reparseHunkRegion(diff, hunkIndex, parseDiffOptions) {
74
+ const hunk = diff.hunks[hunkIndex];
75
+ if (hunk == null) return false;
76
+ const deletionSlice = diff.deletionLines.slice(hunk.deletionLineIndex, hunk.deletionLineIndex + hunk.deletionCount);
77
+ const additionSlice = diff.additionLines.slice(hunk.additionLineIndex, hunk.additionLineIndex + hunk.additionCount);
78
+ const reparsed = parseDiffFromFile({
79
+ name: diff.prevName ?? diff.name,
80
+ contents: deletionSlice.join("")
81
+ }, {
82
+ name: diff.name,
83
+ contents: additionSlice.join(""),
84
+ lang: diff.lang
85
+ }, {
86
+ ...parseDiffOptions,
87
+ context: 0
88
+ });
89
+ const reparsedHunk = reparsed.hunks[0];
90
+ if (reparsedHunk == null || reparsed.hunks.length !== 1) return false;
91
+ applyReparsedHunk(hunk, reparsedHunk);
92
+ syncHunkNoEOFCRFromFullFile(diff, hunkIndex);
93
+ return true;
94
+ }
95
+ function syncHunkNoEOFCRFromFullFile(diff, hunkIndex) {
96
+ const hunk = diff.hunks[hunkIndex];
97
+ if (hunk == null) return;
98
+ if (!(hunkIndex === diff.hunks.length - 1)) {
99
+ hunk.noEOFCRAdditions = false;
100
+ hunk.noEOFCRDeletions = false;
101
+ return;
102
+ }
103
+ const lastAdditionLine = diff.additionLines.at(-1);
104
+ const lastDeletionLine = diff.deletionLines.at(-1);
105
+ hunk.noEOFCRAdditions = lastAdditionLine != null && lastAdditionLine !== "" && !lastAdditionLine.endsWith("\n");
106
+ hunk.noEOFCRDeletions = lastDeletionLine != null && lastDeletionLine !== "" && !lastDeletionLine.endsWith("\n");
107
+ }
108
+ function applyReparsedHunk(target, parsed) {
109
+ const additionOffset = target.additionLineIndex;
110
+ const deletionOffset = target.deletionLineIndex;
111
+ target.hunkContent = parsed.hunkContent.map((content) => offsetHunkContent(content, additionOffset, deletionOffset));
112
+ target.additionLineIndex = additionOffset + parsed.additionLineIndex;
113
+ target.additionStart = target.additionStart + parsed.additionLineIndex;
114
+ target.additionCount = parsed.additionCount;
115
+ target.additionLines = parsed.additionLines;
116
+ if (parsed.deletionLineIndex >= 0) {
117
+ target.deletionLineIndex = deletionOffset + parsed.deletionLineIndex;
118
+ target.deletionStart = target.deletionStart + parsed.deletionLineIndex;
119
+ }
120
+ target.deletionCount = parsed.deletionCount;
121
+ target.deletionLines = parsed.deletionLines;
122
+ target.noEOFCRAdditions = parsed.noEOFCRAdditions;
123
+ target.noEOFCRDeletions = parsed.noEOFCRDeletions;
124
+ recomputeHunkRenderLineCounts(target);
125
+ }
126
+ function offsetHunkContent(content, additionOffset, deletionOffset) {
127
+ return {
128
+ ...content,
129
+ additionLineIndex: content.additionLineIndex + additionOffset,
130
+ deletionLineIndex: content.deletionLineIndex + deletionOffset
131
+ };
132
+ }
133
+ function recomputeHunkRenderLineCounts(hunk) {
134
+ let splitLineCount = 0;
135
+ let unifiedLineCount = 0;
136
+ for (const content of hunk.hunkContent) if (content.type === "context") {
137
+ splitLineCount += content.lines;
138
+ unifiedLineCount += content.lines;
139
+ } else {
140
+ splitLineCount += Math.max(content.additions, content.deletions);
141
+ unifiedLineCount += content.additions + content.deletions;
142
+ }
143
+ hunk.splitLineCount = splitLineCount;
144
+ hunk.unifiedLineCount = unifiedLineCount;
145
+ }
146
+ function recomputeDiffRenderLineCounts(diff) {
147
+ let splitTotal = 0;
148
+ let unifiedTotal = 0;
149
+ let lastHunkAdditionEnd = 0;
150
+ for (const hunk of diff.hunks) {
151
+ hunk.collapsedBefore = Math.max(hunk.additionStart - 1 - lastHunkAdditionEnd, 0);
152
+ hunk.splitLineStart = splitTotal + hunk.collapsedBefore;
153
+ hunk.unifiedLineStart = unifiedTotal + hunk.collapsedBefore;
154
+ recomputeHunkRenderLineCounts(hunk);
155
+ splitTotal += hunk.collapsedBefore + hunk.splitLineCount;
156
+ unifiedTotal += hunk.collapsedBefore + hunk.unifiedLineCount;
157
+ lastHunkAdditionEnd = hunk.additionStart + hunk.additionCount - 1;
158
+ }
159
+ if (diff.hunks.length > 0) {
160
+ const lastHunk = diff.hunks[diff.hunks.length - 1];
161
+ const collapsedAfter = Math.max(diff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount), 0);
162
+ splitTotal += collapsedAfter;
163
+ unifiedTotal += collapsedAfter;
164
+ }
165
+ diff.splitLineCount = splitTotal;
166
+ diff.unifiedLineCount = unifiedTotal;
167
+ }
168
+
169
+ //#endregion
170
+ export { recomputeDiffHunks, updateDiffHunks };
171
+ //# sourceMappingURL=updateDiffHunks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateDiffHunks.js","names":[],"sources":["../../src/utils/updateDiffHunks.ts"],"sourcesContent":["import type { CreatePatchOptionsNonabortable } from 'diff';\n\nimport type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseDiffFromFile } from './parseDiffFromFile';\nimport { hasTrailingContextMismatch } from './virtualDiffLayout';\n\ntype HunkContent = ContextContent | ChangeContent;\n\ntype HunkMetadataUpdate = Pick<\n FileDiffMetadata,\n 'hunks' | 'splitLineCount' | 'unifiedLineCount' | 'type'\n>;\n\ntype FullDiffHunkUpdate = HunkMetadataUpdate &\n Pick<FileDiffMetadata, 'additionLines' | 'deletionLines'>;\n\n/** Rebuilds all hunk metadata from the current deletion/addition line arrays. */\nexport function recomputeDiffHunks(\n diff: FileDiffMetadata,\n parseDiffOptions?: CreatePatchOptionsNonabortable\n): FullDiffHunkUpdate {\n const recomputed = parseDiffFromFile(\n {\n name: diff.prevName ?? diff.name,\n contents: diff.deletionLines.join(''),\n },\n {\n name: diff.name,\n contents: diff.additionLines.join(''),\n lang: diff.lang,\n },\n parseDiffOptions\n );\n return {\n hunks: recomputed.hunks,\n splitLineCount: recomputed.splitLineCount,\n unifiedLineCount: recomputed.unifiedLineCount,\n additionLines: recomputed.additionLines,\n deletionLines: recomputed.deletionLines,\n type: recomputed.type,\n };\n}\n\n/** Updates hunk metadata after addition lines change; re-parses affected hunks only. */\nexport function updateDiffHunks(\n diff: FileDiffMetadata,\n changedAdditionLineIndexes: Iterable<number>,\n parseDiffOptions?: CreatePatchOptionsNonabortable\n): HunkMetadataUpdate {\n if (diff.isPartial) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n\n if (diff.deletionLines.length !== diff.additionLines.length) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n\n const changedLines = Array.from(changedAdditionLineIndexes);\n if (changedLines.length === 0) {\n return applyHunkUpdateResult(diff, {\n hunks: diff.hunks,\n splitLineCount: diff.splitLineCount,\n unifiedLineCount: diff.unifiedLineCount,\n type: diff.type,\n });\n }\n for (const line of changedLines) {\n const additionLine = diff.additionLines[line];\n const deletionLine = diff.deletionLines[line];\n if (additionLine == null || deletionLine == null) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n // Restoring a line to the old side can merge/split hunks across context windows.\n if (cleanLastNewline(additionLine) === cleanLastNewline(deletionLine)) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n }\n\n const affectedHunkIndexes = getAffectedHunkIndexes(diff, changedLines);\n if (affectedHunkIndexes.size === 0) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n\n for (const hunkIndex of affectedHunkIndexes) {\n const updated = reparseHunkRegion(diff, hunkIndex, parseDiffOptions);\n if (!updated) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n }\n\n recomputeDiffRenderLineCounts(diff);\n\n if (hasTrailingContextMismatch(diff)) {\n return applyHunkUpdateResult(\n diff,\n recomputeDiffHunks(diff, parseDiffOptions)\n );\n }\n\n return applyHunkUpdateResult(diff, {\n hunks: diff.hunks,\n splitLineCount: diff.splitLineCount,\n unifiedLineCount: diff.unifiedLineCount,\n type: diff.type,\n });\n}\n\nfunction applyHunkUpdateResult<T extends HunkMetadataUpdate>(\n diff: FileDiffMetadata,\n result: T\n): T {\n Object.assign(diff, result);\n return result;\n}\n\nfunction getAffectedHunkIndexes(\n diff: FileDiffMetadata,\n changedAdditionLineIndexes: Iterable<number>\n): Set<number> {\n const indexes = new Set<number>();\n for (const line of changedAdditionLineIndexes) {\n const hunkIndex = findHunkIndexForAdditionLine(diff, line);\n if (hunkIndex == null) {\n return new Set();\n }\n indexes.add(hunkIndex);\n }\n return indexes;\n}\n\nfunction findHunkIndexForAdditionLine(\n diff: FileDiffMetadata,\n line: number\n): number | undefined {\n for (const [hunkIndex, hunk] of diff.hunks.entries()) {\n const end = hunk.additionLineIndex + hunk.additionCount;\n if (line >= hunk.additionLineIndex && line < end) {\n return hunkIndex;\n }\n }\n return undefined;\n}\n\nfunction reparseHunkRegion(\n diff: FileDiffMetadata,\n hunkIndex: number,\n parseDiffOptions?: CreatePatchOptionsNonabortable\n): boolean {\n const hunk = diff.hunks[hunkIndex];\n if (hunk == null) {\n return false;\n }\n\n const deletionSlice = diff.deletionLines.slice(\n hunk.deletionLineIndex,\n hunk.deletionLineIndex + hunk.deletionCount\n );\n const additionSlice = diff.additionLines.slice(\n hunk.additionLineIndex,\n hunk.additionLineIndex + hunk.additionCount\n );\n\n const reparsed = parseDiffFromFile(\n {\n name: diff.prevName ?? diff.name,\n contents: deletionSlice.join(''),\n },\n {\n name: diff.name,\n contents: additionSlice.join(''),\n lang: diff.lang,\n },\n { ...parseDiffOptions, context: 0 }\n );\n\n const reparsedHunk = reparsed.hunks[0];\n if (reparsedHunk == null || reparsed.hunks.length !== 1) {\n return false;\n }\n\n applyReparsedHunk(hunk, reparsedHunk);\n syncHunkNoEOFCRFromFullFile(diff, hunkIndex);\n return true;\n}\n\nfunction syncHunkNoEOFCRFromFullFile(\n diff: FileDiffMetadata,\n hunkIndex: number\n): void {\n const hunk = diff.hunks[hunkIndex];\n if (hunk == null) {\n return;\n }\n\n const isLastHunk = hunkIndex === diff.hunks.length - 1;\n if (!isLastHunk) {\n hunk.noEOFCRAdditions = false;\n hunk.noEOFCRDeletions = false;\n return;\n }\n\n const lastAdditionLine = diff.additionLines.at(-1);\n const lastDeletionLine = diff.deletionLines.at(-1);\n hunk.noEOFCRAdditions =\n lastAdditionLine != null &&\n lastAdditionLine !== '' &&\n !lastAdditionLine.endsWith('\\n');\n hunk.noEOFCRDeletions =\n lastDeletionLine != null &&\n lastDeletionLine !== '' &&\n !lastDeletionLine.endsWith('\\n');\n}\n\nfunction applyReparsedHunk(target: Hunk, parsed: Hunk): void {\n const additionOffset = target.additionLineIndex;\n const deletionOffset = target.deletionLineIndex;\n\n target.hunkContent = parsed.hunkContent.map((content) =>\n offsetHunkContent(content, additionOffset, deletionOffset)\n );\n target.additionLineIndex = additionOffset + parsed.additionLineIndex;\n target.additionStart = target.additionStart + parsed.additionLineIndex;\n target.additionCount = parsed.additionCount;\n target.additionLines = parsed.additionLines;\n if (parsed.deletionLineIndex >= 0) {\n target.deletionLineIndex = deletionOffset + parsed.deletionLineIndex;\n target.deletionStart = target.deletionStart + parsed.deletionLineIndex;\n }\n target.deletionCount = parsed.deletionCount;\n target.deletionLines = parsed.deletionLines;\n target.noEOFCRAdditions = parsed.noEOFCRAdditions;\n target.noEOFCRDeletions = parsed.noEOFCRDeletions;\n\n recomputeHunkRenderLineCounts(target);\n}\n\nfunction offsetHunkContent(\n content: HunkContent,\n additionOffset: number,\n deletionOffset: number\n): HunkContent {\n return {\n ...content,\n additionLineIndex: content.additionLineIndex + additionOffset,\n deletionLineIndex: content.deletionLineIndex + deletionOffset,\n };\n}\n\nfunction recomputeHunkRenderLineCounts(hunk: Hunk): void {\n let splitLineCount = 0;\n let unifiedLineCount = 0;\n\n for (const content of hunk.hunkContent) {\n if (content.type === 'context') {\n splitLineCount += content.lines;\n unifiedLineCount += content.lines;\n } else {\n splitLineCount += Math.max(content.additions, content.deletions);\n unifiedLineCount += content.additions + content.deletions;\n }\n }\n\n hunk.splitLineCount = splitLineCount;\n hunk.unifiedLineCount = unifiedLineCount;\n}\n\nfunction recomputeDiffRenderLineCounts(diff: FileDiffMetadata): void {\n let splitTotal = 0;\n let unifiedTotal = 0;\n let lastHunkAdditionEnd = 0;\n\n for (const hunk of diff.hunks) {\n hunk.collapsedBefore = Math.max(\n hunk.additionStart - 1 - lastHunkAdditionEnd,\n 0\n );\n hunk.splitLineStart = splitTotal + hunk.collapsedBefore;\n hunk.unifiedLineStart = unifiedTotal + hunk.collapsedBefore;\n\n recomputeHunkRenderLineCounts(hunk);\n\n splitTotal += hunk.collapsedBefore + hunk.splitLineCount;\n unifiedTotal += hunk.collapsedBefore + hunk.unifiedLineCount;\n lastHunkAdditionEnd = hunk.additionStart + hunk.additionCount - 1;\n }\n\n if (diff.hunks.length > 0) {\n const lastHunk = diff.hunks[diff.hunks.length - 1];\n const collapsedAfter = Math.max(\n diff.additionLines.length -\n (lastHunk.additionLineIndex + lastHunk.additionCount),\n 0\n );\n splitTotal += collapsedAfter;\n unifiedTotal += collapsedAfter;\n }\n\n diff.splitLineCount = splitTotal;\n diff.unifiedLineCount = unifiedTotal;\n}\n"],"mappings":";;;;;;AAuBA,SAAgB,mBACd,MACA,kBACoB;CACpB,MAAM,aAAa,kBACjB;EACE,MAAM,KAAK,YAAY,KAAK;EAC5B,UAAU,KAAK,cAAc,KAAK,GAAG;EACtC,EACD;EACE,MAAM,KAAK;EACX,UAAU,KAAK,cAAc,KAAK,GAAG;EACrC,MAAM,KAAK;EACZ,EACD,iBACD;AACD,QAAO;EACL,OAAO,WAAW;EAClB,gBAAgB,WAAW;EAC3B,kBAAkB,W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,MAA8B;CACnE,IAAI,aAAa;CACjB,IAAI,eAAe;CACnB,IAAI,sBAAsB;AAE1B,MAAK,MAAM,QAAQ,KAAK,OAAO;AAC7B,OAAK,kBAAkB,KAAK,IAC1B,KAAK,gBAAgB,IAAI,qBACzB,EACD;AACD,OAAK,iBAAiB,aAAa,KAAK;AACxC,OAAK,mBAAmB,eAAe,KAAK;AAE5C,gCAA8B,KAAK;AAEnC,gBAAc,KAAK,kBAAkB,KAAK;AAC1C,kBAAgB,KAAK,kBAAkB,KAAK;AAC5C,wBAAsB,KAAK,gBAAgB,KAAK,gBAAgB;;AAGlE,KAAI,KAAK,MAAM,SAAS,GAAG;EACzB,MAAM,WAAW,KAAK,MAAM,KAAK,MAAM,SAAS;EAChD,MAAM,iBAAiB,KAAK,IAC1B,KAAK,cAAc,UAChB,SAAS,oBAAoB,SAAS,gBACzC,EACD;AACD,gBAAc;AACd,kBAAgB;;AAGlB,MAAK,iBAAiB;AACtB,MAAK,mBAAmB"}
@@ -1,4 +1,4 @@
1
- import { HunkExpansionRegion, HunkSeparators, VirtualFileMetrics } from "../types.js";
1
+ import { FileDiffMetadata, HunkExpansionRegion, HunkSeparators, VirtualFileMetrics } from "../types.js";
2
2
 
3
3
  //#region src/utils/virtualDiffLayout.d.ts
4
4
  interface ExpandedRegionResult {
@@ -15,6 +15,15 @@ interface GetExpandedRegionProps {
15
15
  hunkIndex: number;
16
16
  collapsedContextThreshold: number;
17
17
  }
18
+ interface GetTrailingContextRangeSizeProps {
19
+ fileDiff: FileDiffMetadata;
20
+ errorPrefix: string;
21
+ }
22
+ interface GetTrailingExpandedRegionProps extends GetTrailingContextRangeSizeProps {
23
+ hunkIndex: number;
24
+ expandedHunks: GetExpandedRegionProps['expandedHunks'];
25
+ collapsedContextThreshold: number;
26
+ }
18
27
  interface HunkSeparatorLayout {
19
28
  height: number;
20
29
  gapBefore: number;
@@ -36,6 +45,19 @@ declare function getExpandedRegion({
36
45
  hunkIndex,
37
46
  collapsedContextThreshold
38
47
  }: GetExpandedRegionProps): ExpandedRegionResult;
48
+ declare function hasTrailingContext(fileDiff: FileDiffMetadata): boolean;
49
+ declare function hasTrailingContextMismatch(fileDiff: FileDiffMetadata): boolean;
50
+ declare function getTrailingContextRangeSize({
51
+ fileDiff,
52
+ errorPrefix
53
+ }: GetTrailingContextRangeSizeProps): number;
54
+ declare function getTrailingExpandedRegion({
55
+ fileDiff,
56
+ hunkIndex,
57
+ expandedHunks,
58
+ collapsedContextThreshold,
59
+ errorPrefix
60
+ }: GetTrailingExpandedRegionProps): ExpandedRegionResult | undefined;
39
61
  declare function getHunkSeparatorHeight({
40
62
  type,
41
63
  metrics
@@ -61,5 +83,5 @@ declare function getTrailingHunkSeparatorLayout({
61
83
  metrics
62
84
  }: HunkSeparatorBaseProps): HunkSeparatorLayout | undefined;
63
85
  //#endregion
64
- export { ExpandedRegionResult, GetExpandedRegionProps, HunkSeparatorLayout, getExpandedRegion, getHunkSeparatorGap, getHunkSeparatorHeight, getLeadingHunkSeparatorLayout, getTrailingHunkSeparatorLayout, hasLeadingHunkSeparator, hasTrailingHunkSeparator };
86
+ export { ExpandedRegionResult, GetExpandedRegionProps, GetTrailingContextRangeSizeProps, GetTrailingExpandedRegionProps, HunkSeparatorLayout, getExpandedRegion, getHunkSeparatorGap, getHunkSeparatorHeight, getLeadingHunkSeparatorLayout, getTrailingContextRangeSize, getTrailingExpandedRegion, getTrailingHunkSeparatorLayout, hasLeadingHunkSeparator, hasTrailingContext, hasTrailingContextMismatch, hasTrailingHunkSeparator };
65
87
  //# sourceMappingURL=virtualDiffLayout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtualDiffLayout.d.ts","names":["HunkExpansionRegion","HunkSeparators","VirtualFileMetrics","ExpandedRegionResult","GetExpandedRegionProps","Map","HunkSeparatorLayout","HunkSeparatorBaseProps","LeadingHunkSeparatorLayoutProps","getExpandedRegion","isPartial","rangeSize","expandedHunks","hunkIndex","collapsedContextThreshold","getHunkSeparatorHeight","type","metrics","getHunkSeparatorGap","hasLeadingHunkSeparator","hunkSpecs","Omit","hasTrailingHunkSeparator","getLeadingHunkSeparatorLayout","getTrailingHunkSeparatorLayout"],"sources":["../../src/utils/virtualDiffLayout.d.ts"],"sourcesContent":["import type { HunkExpansionRegion, HunkSeparators, VirtualFileMetrics } from '../types';\nexport interface ExpandedRegionResult {\n fromStart: number;\n fromEnd: number;\n rangeSize: number;\n collapsedLines: number;\n renderAll: boolean;\n}\nexport interface GetExpandedRegionProps {\n isPartial: boolean;\n rangeSize: number;\n expandedHunks: Map<number, HunkExpansionRegion> | true | undefined;\n hunkIndex: number;\n collapsedContextThreshold: number;\n}\nexport interface HunkSeparatorLayout {\n height: number;\n gapBefore: number;\n gapAfter: number;\n totalHeight: number;\n}\ninterface HunkSeparatorBaseProps {\n type: HunkSeparators;\n metrics: VirtualFileMetrics;\n}\ninterface LeadingHunkSeparatorLayoutProps extends HunkSeparatorBaseProps {\n hunkIndex: number;\n hunkSpecs: string | undefined;\n}\nexport declare function getExpandedRegion({ isPartial, rangeSize, expandedHunks, hunkIndex, collapsedContextThreshold }: GetExpandedRegionProps): ExpandedRegionResult;\nexport declare function getHunkSeparatorHeight({ type, metrics }: HunkSeparatorBaseProps): number;\nexport declare function getHunkSeparatorGap({ type, metrics }: HunkSeparatorBaseProps): number;\nexport declare function hasLeadingHunkSeparator({ type, hunkIndex, hunkSpecs }: Omit<LeadingHunkSeparatorLayoutProps, 'metrics'>): boolean;\nexport declare function hasTrailingHunkSeparator(type: HunkSeparators): boolean;\nexport declare function getLeadingHunkSeparatorLayout({ type, metrics, hunkIndex, hunkSpecs }: LeadingHunkSeparatorLayoutProps): HunkSeparatorLayout | undefined;\nexport declare function getTrailingHunkSeparatorLayout({ type, metrics }: HunkSeparatorBaseProps): HunkSeparatorLayout | undefined;\nexport {};\n//# sourceMappingURL=virtualDiffLayout.d.ts.map"],"mappings":";;;UACiBG,oBAAAA;;EAAAA,OAAAA,EAAAA,MAAAA;EAOAC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AAA,CAD4D,IAAA,EAC7BrB,cAD6B,CAAA,EAAA,OAAA;AAC5DqB,iBACAC,6BAAAA,CAD+BtB;EAAAA,IAAc;EAAA,OAAA;EAAA,SAAA;EAAA;AAAA,CAAA,EAC0BO,+BAD1B,CAAA,EAC4DF,mBAD5D,GAAA,SAAA;AAC7CiB,iBACAC,8BAAAA,CAD6B;EAAA,IAAA;EAAA;AAAA,CAAA,EACqBjB,sBADrB,CAAA,EAC8CD,mBAD9C,GAAA,SAAA"}
1
+ {"version":3,"file":"virtualDiffLayout.d.ts","names":["FileDiffMetadata","HunkExpansionRegion","HunkSeparators","VirtualFileMetrics","ExpandedRegionResult","GetExpandedRegionProps","Map","GetTrailingContextRangeSizeProps","GetTrailingExpandedRegionProps","HunkSeparatorLayout","HunkSeparatorBaseProps","LeadingHunkSeparatorLayoutProps","getExpandedRegion","isPartial","rangeSize","expandedHunks","hunkIndex","collapsedContextThreshold","hasTrailingContext","hasTrailingContextMismatch","getTrailingContextRangeSize","fileDiff","errorPrefix","getTrailingExpandedRegion","getHunkSeparatorHeight","type","metrics","getHunkSeparatorGap","hasLeadingHunkSeparator","hunkSpecs","Omit","hasTrailingHunkSeparator","getLeadingHunkSeparatorLayout","getTrailingHunkSeparatorLayout"],"sources":["../../src/utils/virtualDiffLayout.d.ts"],"sourcesContent":["import type { FileDiffMetadata, HunkExpansionRegion, HunkSeparators, VirtualFileMetrics } from '../types';\nexport interface ExpandedRegionResult {\n fromStart: number;\n fromEnd: number;\n rangeSize: number;\n collapsedLines: number;\n renderAll: boolean;\n}\nexport interface GetExpandedRegionProps {\n isPartial: boolean;\n rangeSize: number;\n expandedHunks: Map<number, HunkExpansionRegion> | true | undefined;\n hunkIndex: number;\n collapsedContextThreshold: number;\n}\nexport interface GetTrailingContextRangeSizeProps {\n fileDiff: FileDiffMetadata;\n errorPrefix: string;\n}\nexport interface GetTrailingExpandedRegionProps extends GetTrailingContextRangeSizeProps {\n hunkIndex: number;\n expandedHunks: GetExpandedRegionProps['expandedHunks'];\n collapsedContextThreshold: number;\n}\nexport interface HunkSeparatorLayout {\n height: number;\n gapBefore: number;\n gapAfter: number;\n totalHeight: number;\n}\ninterface HunkSeparatorBaseProps {\n type: HunkSeparators;\n metrics: VirtualFileMetrics;\n}\ninterface LeadingHunkSeparatorLayoutProps extends HunkSeparatorBaseProps {\n hunkIndex: number;\n hunkSpecs: string | undefined;\n}\nexport declare function getExpandedRegion({ isPartial, rangeSize, expandedHunks, hunkIndex, collapsedContextThreshold }: GetExpandedRegionProps): ExpandedRegionResult;\nexport declare function hasTrailingContext(fileDiff: FileDiffMetadata): boolean;\nexport declare function hasTrailingContextMismatch(fileDiff: FileDiffMetadata): boolean;\nexport declare function getTrailingContextRangeSize({ fileDiff, errorPrefix }: GetTrailingContextRangeSizeProps): number;\nexport declare function getTrailingExpandedRegion({ fileDiff, hunkIndex, expandedHunks, collapsedContextThreshold, errorPrefix }: GetTrailingExpandedRegionProps): ExpandedRegionResult | undefined;\nexport declare function getHunkSeparatorHeight({ type, metrics }: HunkSeparatorBaseProps): number;\nexport declare function getHunkSeparatorGap({ type, metrics }: HunkSeparatorBaseProps): number;\nexport declare function hasLeadingHunkSeparator({ type, hunkIndex, hunkSpecs }: Omit<LeadingHunkSeparatorLayoutProps, 'metrics'>): boolean;\nexport declare function hasTrailingHunkSeparator(type: HunkSeparators): boolean;\nexport declare function getLeadingHunkSeparatorLayout({ type, metrics, hunkIndex, hunkSpecs }: LeadingHunkSeparatorLayoutProps): HunkSeparatorLayout | undefined;\nexport declare function getTrailingHunkSeparatorLayout({ type, metrics }: HunkSeparatorBaseProps): HunkSeparatorLayout | undefined;\nexport {};\n//# sourceMappingURL=virtualDiffLayout.d.ts.map"],"mappings":";;;UACiBI,oBAAAA;;EAAAA,OAAAA,EAAAA,MAAAA;EAOAC,SAAAA,EAAAA,MAAAA;EAOAE,cAAAA,EAAAA,MAAAA;EAIAC,SAAAA,EAAAA,OAAAA;AAKjB;AAMUE,UAtBOL,sBA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AHiClB,gCAGjCkB,CAAAA,EAAAA,MAAAA;AAAMC,iBAF5BH,yBAAAA,CAE4BG;EAAAA,QAAAA;EAAAA,SAAAA;EAAAA,aAAAA;EAAAA,yBAAAA;EAAAA;AAAAA,CAAAA,EAF8ElB,8BAE9EkB,CAAAA,EAF+GtB,oBAE/GsB,GAAAA,SAAAA;AAAWhB,iBADvCc,sBAAAA,CACuCd;EAAAA,IAAAA;EAAAA;AAAAA,CAAAA,EADGA,sBACHA,CAAAA,EAAAA,MAAAA;AAAsB,iBAA7DiB,mBAAAA,CAA6D;EAAA,IAAA;EAAA;AAAA,CAAA,EAAtBjB,sBAAsB,CAAA,EAAA,MAAA;AAC7DkB,iBAAAA,uBAAAA,CAAuB;EAAA,IAAA;EAAA,SAAA;EAAA;AAAA,CAAA,EAAiCE,IAAjC,CAAsCnB,+BAAtC,EAAA,SAAA,CAAA,CAAA,EAAA,OAAA;AAAGc,iBAC1BM,wBAAAA,CAD0BN,IAAAA,EACKvB,cADLuB,CAAAA,EAAAA,OAAAA;AAAMT,iBAEhCgB,6BAAAA,CAFgChB;EAAAA,IAAAA;EAAAA,OAAAA;EAAAA,SAAAA;EAAAA;AAAAA,CAAAA,EAEuCL,+BAFvCK,CAAAA,EAEyEP,mBAFzEO,GAAAA,SAAAA;AAAWa,iBAG3CI,8BAAAA,CAH2CJ;EAAAA,IAAAA;EAAAA;AAAAA,CAAAA,EAGOnB,sBAHPmB,CAAAA,EAGgCpB,mBAHhCoB,GAAAA,SAAAA"}
@@ -30,6 +30,54 @@ function getExpandedRegion({ isPartial, rangeSize, expandedHunks, hunkIndex, col
30
30
  renderAll
31
31
  };
32
32
  }
33
+ function hasTrailingContext(fileDiff) {
34
+ const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];
35
+ if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) return false;
36
+ const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
37
+ const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
38
+ return additionRemaining > 0 || deletionRemaining > 0;
39
+ }
40
+ function hasTrailingContextMismatch(fileDiff) {
41
+ const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];
42
+ if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) return false;
43
+ const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
44
+ const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
45
+ if (additionRemaining <= 0 && deletionRemaining <= 0) return false;
46
+ return additionRemaining !== deletionRemaining;
47
+ }
48
+ function getTrailingContextRangeSize({ fileDiff, errorPrefix }) {
49
+ const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];
50
+ if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) return 0;
51
+ const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
52
+ const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
53
+ if (additionRemaining <= 0 && deletionRemaining <= 0) return 0;
54
+ if (additionRemaining !== deletionRemaining) throw new Error(`${errorPrefix}: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${fileDiff.name}`);
55
+ return Math.min(additionRemaining, deletionRemaining);
56
+ }
57
+ function getTrailingExpandedRegion({ fileDiff, hunkIndex, expandedHunks, collapsedContextThreshold, errorPrefix }) {
58
+ if (hunkIndex !== fileDiff.hunks.length - 1) return;
59
+ const trailingRangeSize = getTrailingContextRangeSize({
60
+ fileDiff,
61
+ errorPrefix
62
+ });
63
+ if (trailingRangeSize <= 0) return;
64
+ if (expandedHunks === true || trailingRangeSize <= collapsedContextThreshold) return {
65
+ fromStart: trailingRangeSize,
66
+ fromEnd: 0,
67
+ rangeSize: trailingRangeSize,
68
+ collapsedLines: 0,
69
+ renderAll: true
70
+ };
71
+ const region = expandedHunks?.get(fileDiff.hunks.length);
72
+ const fromStart = Math.min(Math.max(region?.fromStart ?? 0, 0), trailingRangeSize);
73
+ return {
74
+ fromStart,
75
+ fromEnd: 0,
76
+ rangeSize: trailingRangeSize,
77
+ collapsedLines: trailingRangeSize - fromStart,
78
+ renderAll: fromStart >= trailingRangeSize
79
+ };
80
+ }
33
81
  function getHunkSeparatorHeight({ type, metrics }) {
34
82
  return metrics.hunkSeparatorHeight ?? getDefaultHunkSeparatorHeight(type);
35
83
  }
@@ -90,5 +138,5 @@ function getTrailingHunkSeparatorLayout({ type, metrics }) {
90
138
  }
91
139
 
92
140
  //#endregion
93
- export { getExpandedRegion, getHunkSeparatorGap, getHunkSeparatorHeight, getLeadingHunkSeparatorLayout, getTrailingHunkSeparatorLayout, hasLeadingHunkSeparator, hasTrailingHunkSeparator };
141
+ export { getExpandedRegion, getHunkSeparatorGap, getHunkSeparatorHeight, getLeadingHunkSeparatorLayout, getTrailingContextRangeSize, getTrailingExpandedRegion, getTrailingHunkSeparatorLayout, hasLeadingHunkSeparator, hasTrailingContext, hasTrailingContextMismatch, hasTrailingHunkSeparator };
94
142
  //# sourceMappingURL=virtualDiffLayout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtualDiffLayout.js","names":[],"sources":["../../src/utils/virtualDiffLayout.ts"],"sourcesContent":["import type {\n HunkExpansionRegion,\n HunkSeparators,\n VirtualFileMetrics,\n} from '../types';\nimport { getDefaultHunkSeparatorHeight } from './computeVirtualFileMetrics';\n\nexport interface ExpandedRegionResult {\n fromStart: number;\n fromEnd: number;\n rangeSize: number;\n collapsedLines: number;\n renderAll: boolean;\n}\n\nexport interface GetExpandedRegionProps {\n isPartial: boolean;\n rangeSize: number;\n expandedHunks: Map<number, HunkExpansionRegion> | true | undefined;\n hunkIndex: number;\n collapsedContextThreshold: number;\n}\n\nexport interface HunkSeparatorLayout {\n height: number;\n gapBefore: number;\n gapAfter: number;\n totalHeight: number;\n}\n\ninterface HunkSeparatorBaseProps {\n type: HunkSeparators;\n metrics: VirtualFileMetrics;\n}\n\ninterface LeadingHunkSeparatorLayoutProps extends HunkSeparatorBaseProps {\n hunkIndex: number;\n hunkSpecs: string | undefined;\n}\n\n// Converts a collapsed unchanged range into the slices that should render near\n// the start and end of that range for the active hunk expansion state.\nexport function getExpandedRegion({\n isPartial,\n rangeSize,\n expandedHunks,\n hunkIndex,\n collapsedContextThreshold,\n}: GetExpandedRegionProps): ExpandedRegionResult {\n const normalizedRangeSize = Math.max(rangeSize, 0);\n if (normalizedRangeSize === 0 || isPartial) {\n return {\n fromStart: 0,\n fromEnd: 0,\n rangeSize: normalizedRangeSize,\n collapsedLines: normalizedRangeSize,\n renderAll: false,\n };\n }\n\n if (\n expandedHunks === true ||\n normalizedRangeSize <= collapsedContextThreshold\n ) {\n return {\n fromStart: normalizedRangeSize,\n fromEnd: 0,\n rangeSize: normalizedRangeSize,\n collapsedLines: 0,\n renderAll: true,\n };\n }\n\n const region = expandedHunks?.get(hunkIndex);\n const fromStart = Math.min(\n Math.max(region?.fromStart ?? 0, 0),\n normalizedRangeSize\n );\n const fromEnd = Math.min(\n Math.max(region?.fromEnd ?? 0, 0),\n normalizedRangeSize\n );\n const expandedCount = fromStart + fromEnd;\n const renderAll = expandedCount >= normalizedRangeSize;\n return {\n fromStart: renderAll ? normalizedRangeSize : fromStart,\n fromEnd: renderAll ? 0 : fromEnd,\n rangeSize: normalizedRangeSize,\n collapsedLines: Math.max(normalizedRangeSize - expandedCount, 0),\n renderAll,\n };\n}\n\nexport function getHunkSeparatorHeight({\n type,\n metrics,\n}: HunkSeparatorBaseProps): number {\n return metrics.hunkSeparatorHeight ?? getDefaultHunkSeparatorHeight(type);\n}\n\nexport function getHunkSeparatorGap({\n type,\n metrics,\n}: HunkSeparatorBaseProps): number {\n return type === 'simple' || type === 'metadata' || type === 'line-info-basic'\n ? 0\n : metrics.spacing;\n}\n\nexport function hasLeadingHunkSeparator({\n type,\n hunkIndex,\n hunkSpecs,\n}: Omit<LeadingHunkSeparatorLayoutProps, 'metrics'>): boolean {\n switch (type) {\n case 'simple':\n return hunkIndex > 0;\n case 'metadata':\n return hunkSpecs != null;\n case 'line-info':\n case 'line-info-basic':\n case 'custom':\n return true;\n }\n}\n\nexport function hasTrailingHunkSeparator(type: HunkSeparators): boolean {\n return type !== 'simple' && type !== 'metadata';\n}\n\n// Mirrors the renderer/CSS spacing rules for the separator shown before a hunk.\nexport function getLeadingHunkSeparatorLayout({\n type,\n metrics,\n hunkIndex,\n hunkSpecs,\n}: LeadingHunkSeparatorLayoutProps): HunkSeparatorLayout | undefined {\n if (!hasLeadingHunkSeparator({ type, hunkIndex, hunkSpecs })) {\n return undefined;\n }\n\n const height = getHunkSeparatorHeight({ type, metrics });\n const gap = getHunkSeparatorGap({ type, metrics });\n const gapBefore = hunkIndex > 0 ? gap : 0;\n const gapAfter = gap;\n return {\n height,\n gapBefore,\n gapAfter,\n totalHeight: gapBefore + height + gapAfter,\n };\n}\n\n// Mirrors the renderer/CSS spacing rules for the separator shown after the last\n// hunk when trailing unchanged context is collapsed.\nexport function getTrailingHunkSeparatorLayout({\n type,\n metrics,\n}: HunkSeparatorBaseProps): HunkSeparatorLayout | undefined {\n if (!hasTrailingHunkSeparator(type)) {\n return undefined;\n }\n\n const height = getHunkSeparatorHeight({ type, metrics });\n const gapBefore = getHunkSeparatorGap({ type, metrics });\n return {\n height,\n gapBefore,\n gapAfter: 0,\n totalHeight: gapBefore + height,\n };\n}\n"],"mappings":";;;AA0CA,SAAgB,kBAAkB,EAChC,WACA,WACA,eACA,WACA,6BAC+C;CAC/C,MAAM,sBAAsB,KAAK,IAAI,WAAW,EAAE;AAClD,KAAI,wBAAwB,KAAK,UAC/B,QAAO;EACL,WAAW;EACX,SAAS;EACT,WAAW;EACX,gBAAgB;EAChB,WAAW;EACZ;AAGH,KACE,kBAAkB,QA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C7C,MACA,WAC0D;AAC1D,KAAI,CAAC,yBAAyB,KAAK,CACjC;CAGF,MAAM,SAAS,uBAAuB;EAAE;EAAM;EAAS,CAAC;CACxD,MAAM,YAAY,oBAAoB;EAAE;EAAM;EAAS,CAAC;AACxD,QAAO;EACL;EACA;EACA,UAAU;EACV,aAAa,YAAY;EAC1B"}
1
+ {"version":3,"file":"virtualDiffLayout.js","names":[],"sources":["../../src/utils/virtualDiffLayout.ts"],"sourcesContent":["import type {\n FileDiffMetadata,\n HunkExpansionRegion,\n HunkSeparators,\n VirtualFileMetrics,\n} from '../types';\nimport { getDefaultHunkSeparatorHeight } from './computeVirtualFileMetrics';\n\nexport interface ExpandedRegionResult {\n fromStart: number;\n fromEnd: number;\n rangeSize: number;\n collapsedLines: number;\n renderAll: boolean;\n}\n\nexport interface GetExpandedRegionProps {\n isPartial: boolean;\n rangeSize: number;\n expandedHunks: Map<number, HunkExpansionRegion> | true | undefined;\n hunkIndex: number;\n collapsedContextThreshold: number;\n}\n\nexport interface GetTrailingContextRangeSizeProps {\n fileDiff: FileDiffMetadata;\n errorPrefix: string;\n}\n\nexport interface GetTrailingExpandedRegionProps extends GetTrailingContextRangeSizeProps {\n hunkIndex: number;\n expandedHunks: GetExpandedRegionProps['expandedHunks'];\n collapsedContextThreshold: number;\n}\n\nexport interface HunkSeparatorLayout {\n height: number;\n gapBefore: number;\n gapAfter: number;\n totalHeight: number;\n}\n\ninterface HunkSeparatorBaseProps {\n type: HunkSeparators;\n metrics: VirtualFileMetrics;\n}\n\ninterface LeadingHunkSeparatorLayoutProps extends HunkSeparatorBaseProps {\n hunkIndex: number;\n hunkSpecs: string | undefined;\n}\n\n// Converts a collapsed unchanged range into the slices that should render near\n// the start and end of that range for the active hunk expansion state.\nexport function getExpandedRegion({\n isPartial,\n rangeSize,\n expandedHunks,\n hunkIndex,\n collapsedContextThreshold,\n}: GetExpandedRegionProps): ExpandedRegionResult {\n const normalizedRangeSize = Math.max(rangeSize, 0);\n if (normalizedRangeSize === 0 || isPartial) {\n return {\n fromStart: 0,\n fromEnd: 0,\n rangeSize: normalizedRangeSize,\n collapsedLines: normalizedRangeSize,\n renderAll: false,\n };\n }\n\n if (\n expandedHunks === true ||\n normalizedRangeSize <= collapsedContextThreshold\n ) {\n return {\n fromStart: normalizedRangeSize,\n fromEnd: 0,\n rangeSize: normalizedRangeSize,\n collapsedLines: 0,\n renderAll: true,\n };\n }\n\n const region = expandedHunks?.get(hunkIndex);\n const fromStart = Math.min(\n Math.max(region?.fromStart ?? 0, 0),\n normalizedRangeSize\n );\n const fromEnd = Math.min(\n Math.max(region?.fromEnd ?? 0, 0),\n normalizedRangeSize\n );\n const expandedCount = fromStart + fromEnd;\n const renderAll = expandedCount >= normalizedRangeSize;\n return {\n fromStart: renderAll ? normalizedRangeSize : fromStart,\n fromEnd: renderAll ? 0 : fromEnd,\n rangeSize: normalizedRangeSize,\n collapsedLines: Math.max(normalizedRangeSize - expandedCount, 0),\n renderAll,\n };\n}\n\nexport function hasTrailingContext(fileDiff: FileDiffMetadata): boolean {\n const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];\n if (\n lastHunk == null ||\n fileDiff.isPartial ||\n fileDiff.additionLines.length === 0 ||\n fileDiff.deletionLines.length === 0\n ) {\n return false;\n }\n\n const additionRemaining =\n fileDiff.additionLines.length -\n (lastHunk.additionLineIndex + lastHunk.additionCount);\n const deletionRemaining =\n fileDiff.deletionLines.length -\n (lastHunk.deletionLineIndex + lastHunk.deletionCount);\n\n return additionRemaining > 0 || deletionRemaining > 0;\n}\n\n// Returns true when trailing-context line counts disagree between sides.\nexport function hasTrailingContextMismatch(\n fileDiff: FileDiffMetadata\n): boolean {\n const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];\n if (\n lastHunk == null ||\n fileDiff.isPartial ||\n fileDiff.additionLines.length === 0 ||\n fileDiff.deletionLines.length === 0\n ) {\n return false;\n }\n\n const additionRemaining =\n fileDiff.additionLines.length -\n (lastHunk.additionLineIndex + lastHunk.additionCount);\n const deletionRemaining =\n fileDiff.deletionLines.length -\n (lastHunk.deletionLineIndex + lastHunk.deletionCount);\n\n if (additionRemaining <= 0 && deletionRemaining <= 0) {\n return false;\n }\n\n return additionRemaining !== deletionRemaining;\n}\n\n// Measures the unchanged tail after the final hunk. Both sides must have the\n// same remaining length because trailing context represents paired lines.\nexport function getTrailingContextRangeSize({\n fileDiff,\n errorPrefix,\n}: GetTrailingContextRangeSizeProps): number {\n const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];\n if (\n lastHunk == null ||\n fileDiff.isPartial ||\n fileDiff.additionLines.length === 0 ||\n fileDiff.deletionLines.length === 0\n ) {\n return 0;\n }\n\n const additionRemaining =\n fileDiff.additionLines.length -\n (lastHunk.additionLineIndex + lastHunk.additionCount);\n const deletionRemaining =\n fileDiff.deletionLines.length -\n (lastHunk.deletionLineIndex + lastHunk.deletionCount);\n\n if (additionRemaining <= 0 && deletionRemaining <= 0) {\n return 0;\n }\n\n if (additionRemaining !== deletionRemaining) {\n throw new Error(\n `${errorPrefix}: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${fileDiff.name}`\n );\n }\n return Math.min(additionRemaining, deletionRemaining);\n}\n\nexport function getTrailingExpandedRegion({\n fileDiff,\n hunkIndex,\n expandedHunks,\n collapsedContextThreshold,\n errorPrefix,\n}: GetTrailingExpandedRegionProps): ExpandedRegionResult | undefined {\n if (hunkIndex !== fileDiff.hunks.length - 1) {\n return undefined;\n }\n\n const trailingRangeSize = getTrailingContextRangeSize({\n fileDiff,\n errorPrefix,\n });\n if (trailingRangeSize <= 0) {\n return undefined;\n }\n\n if (\n expandedHunks === true ||\n trailingRangeSize <= collapsedContextThreshold\n ) {\n return {\n fromStart: trailingRangeSize,\n fromEnd: 0,\n rangeSize: trailingRangeSize,\n collapsedLines: 0,\n renderAll: true,\n };\n }\n\n // The final trailing separator only exposes upward partial expansion. Treat it\n // as a bottom-only pseudo-hunk and ignore unsupported downward expansion.\n const region = expandedHunks?.get(fileDiff.hunks.length);\n const fromStart = Math.min(\n Math.max(region?.fromStart ?? 0, 0),\n trailingRangeSize\n );\n return {\n fromStart,\n fromEnd: 0,\n rangeSize: trailingRangeSize,\n collapsedLines: trailingRangeSize - fromStart,\n renderAll: fromStart >= trailingRangeSize,\n };\n}\n\nexport function getHunkSeparatorHeight({\n type,\n metrics,\n}: HunkSeparatorBaseProps): number {\n return metrics.hunkSeparatorHeight ?? getDefaultHunkSeparatorHeight(type);\n}\n\nexport function getHunkSeparatorGap({\n type,\n metrics,\n}: HunkSeparatorBaseProps): number {\n return type === 'simple' || type === 'metadata' || type === 'line-info-basic'\n ? 0\n : metrics.spacing;\n}\n\nexport function hasLeadingHunkSeparator({\n type,\n hunkIndex,\n hunkSpecs,\n}: Omit<LeadingHunkSeparatorLayoutProps, 'metrics'>): boolean {\n switch (type) {\n case 'simple':\n return hunkIndex > 0;\n case 'metadata':\n return hunkSpecs != null;\n case 'line-info':\n case 'line-info-basic':\n case 'custom':\n return true;\n }\n}\n\nexport function hasTrailingHunkSeparator(type: HunkSeparators): boolean {\n return type !== 'simple' && type !== 'metadata';\n}\n\n// Mirrors the renderer/CSS spacing rules for the separator shown before a hunk.\nexport function getLeadingHunkSeparatorLayout({\n type,\n metrics,\n hunkIndex,\n hunkSpecs,\n}: LeadingHunkSeparatorLayoutProps): HunkSeparatorLayout | undefined {\n if (!hasLeadingHunkSeparator({ type, hunkIndex, hunkSpecs })) {\n return undefined;\n }\n\n const height = getHunkSeparatorHeight({ type, metrics });\n const gap = getHunkSeparatorGap({ type, metrics });\n const gapBefore = hunkIndex > 0 ? gap : 0;\n const gapAfter = gap;\n return {\n height,\n gapBefore,\n gapAfter,\n totalHeight: gapBefore + height + gapAfter,\n };\n}\n\n// Mirrors the renderer/CSS spacing rules for the separator shown after the last\n// hunk when trailing unchanged context is collapsed.\nexport function getTrailingHunkSeparatorLayout({\n type,\n metrics,\n}: HunkSeparatorBaseProps): HunkSeparatorLayout | undefined {\n if (!hasTrailingHunkSeparator(type)) {\n return undefined;\n }\n\n const height = getHunkSeparatorHeight({ type, metrics });\n const gapBefore = getHunkSeparatorGap({ type, metrics });\n return {\n height,\n gapBefore,\n gapAfter: 0,\n totalHeight: gapBefore + height,\n };\n}\n"],"mappings":";;;AAsDA,SAAgB,kBAAkB,EAChC,WACA,WACA,eACA,WACA,6BAC+C;CAC/C,MAAM,sBAAsB,KAAK,IAAI,WAAW,EAAE;AAClD,KAAI,wBAAwB,KAAK,UAC/B,QAAO;EACL,WAAW;EACX,SAAS;EACT,WAAW;EACX,gBAAgB;EAChB,WAAW;EACZ;AAGH,KACE,kBAAkB,QAClB,uBAAuB,0BAEvB,QAAO;EACL,WAAW;EACX,SAAS;EACT,WAAW;EACX,gBAAgB;EAChB,WAAW;EACZ;CAGH,MAAM,SAAS,eAAe,IAAI,UAAU;CAC5C,MAAM,YAAY,KAAK,IACrB,KAAK,IAAI,QAAQ,aAAa,GAAG,EAAE,EACnC,oBACD;CACD,MAAM,UAAU,KAAK,IACnB,KAAK,IAAI,QAAQ,WAAW,GAAG,EAAE,EACjC,oBACD;CACD,MAAM,gBAAgB,YAAY;CAClC,MAAM,YAAY,iBAAiB;AACnC,QAAO;EACL,WAAW,YAAY,sBAAsB;EAC7C,SAAS,YAAY,IAAI;EACzB,WAAW;EACX,gBAAgB,KAAK,IAAI,sBAAsB,eAAe,EAAE;EAChE;EACD;;AAGH,SAAgB,mBAAmB,UAAqC;CACtE,MAAM,WAAW,SAAS,MAAM,SAAS,MAAM,SAAS;AACxD,KACE,YAAY,QACZ,SAAS,aACT,SAAS,cAAc,WAAW,KAClC,SAAS,cAAc,WAAW,EAElC,QAAO;CAGT,MAAM,oBACJ,SAAS,cAAc,UACtB,SAAS,oBAAoB,SAAS;CACzC,MAAM,oBACJ,SAAS,cAAc,UACtB,SAAS,oBAAoB,SAAS;AAEzC,QAAO,oBAAoB,KAAK,oBAAoB;;AAItD,SAAgB,2BACd,UACS;CACT,MAAM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ACA,SAAS;EACT,WAAW;EACX,gBAAgB,oBAAoB;EACpC,WAAW,aAAa;EACzB;;AAGH,SAAgB,uBAAuB,EACrC,MACA,WACiC;AACjC,QAAO,QAAQ,uBAAuB,8BAA8B,KAAK;;AAG3E,SAAgB,oBAAoB,EAClC,MACA,WACiC;AACjC,QAAO,SAAS,YAAY,SAAS,cAAc,SAAS,oBACxD,IACA,QAAQ;;AAGd,SAAgB,wBAAwB,EACtC,MACA,WACA,aAC4D;AAC5D,SAAQ,MAAR;EACE,KAAK,SACH,QAAO,YAAY;EACrB,KAAK,WACH,QAAO,aAAa;EACtB,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO;;;AAIb,SAAgB,yBAAyB,MAA+B;AACtE,QAAO,SAAS,YAAY,SAAS;;AAIvC,SAAgB,8BAA8B,EAC5C,MACA,SACA,WACA,aACmE;AACnE,KAAI,CAAC,wBAAwB;EAAE;EAAM;EAAW;EAAW,CAAC,CAC1D;CAGF,MAAM,SAAS,uBAAuB;EAAE;EAAM;EAAS,CAAC;CACxD,MAAM,MAAM,oBAAoB;EAAE;EAAM;EAAS,CAAC;CAClD,MAAM,YAAY,YAAY,IAAI,MAAM;CACxC,MAAM,WAAW;AACjB,QAAO;EACL;EACA;EACA;EACA,aAAa,YAAY,SAAS;EACnC;;AAKH,SAAgB,+BAA+B,EAC7C,MACA,WAC0D;AAC1D,KAAI,CAAC,yBAAyB,KAAK,CACjC;CAGF,MAAM,SAAS,uBAAuB;EAAE;EAAM;EAAS,CAAC;CACxD,MAAM,YAAY,oBAAoB;EAAE;EAAM;EAAS,CAAC;AACxD,QAAO;EACL;EACA;EACA,UAAU;EACV,aAAa,YAAY;EAC1B"}
@@ -92,7 +92,7 @@ var WorkerPoolManager = class {
92
92
  this.queueBroadcastStateChanges();
93
93
  }
94
94
  }
95
- async setRenderOptions({ theme = DEFAULT_THEMES, useTokenTransformer = false, lineDiffType = "word-alt", maxLineDiffLength = 1e3, tokenizeMaxLineLength = 1e3 }) {
95
+ async setRenderOptions({ theme = this.renderOptions.theme ?? DEFAULT_THEMES, useTokenTransformer = this.renderOptions.useTokenTransformer ?? false, lineDiffType = this.renderOptions.lineDiffType ?? "word-alt", maxLineDiffLength = this.renderOptions.maxLineDiffLength ?? 1e3, tokenizeMaxLineLength = this.renderOptions.tokenizeMaxLineLength ?? 1e3 }) {
96
96
  const { lifecycleGeneration } = this;
97
97
  const renderOptionsRequestVersion = ++this.renderOptionsRequestVersion;
98
98
  const isCurrentRequest = () => this.isCurrentLifecycle(lifecycleGeneration) && this.renderOptionsRequestVersion === renderOptionsRequestVersion;