@pierre/diffs 1.2.5 → 1.2.6
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.map +1 -1
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +16 -41
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.js +5 -3
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +5 -9
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +9 -20
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/iterateOverDiff.js +147 -182
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/virtualDiffLayout.d.ts +23 -2
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +41 -1
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/worker-portable.js +213 -214
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +179 -181
- package/dist/worker/worker.js.map +1 -1
- package/package.json +20 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_COLLAPSED_CONTEXT_THRESHOLD } from "../constants.js";
|
|
2
|
-
import { getExpandedRegion } from "./virtualDiffLayout.js";
|
|
2
|
+
import { getExpandedRegion, getTrailingExpandedRegion } from "./virtualDiffLayout.js";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/iterateOverDiff.ts
|
|
5
5
|
function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infinity, expandedHunks, collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD, callback }) {
|
|
@@ -11,12 +11,12 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
11
11
|
collapsedContextThreshold
|
|
12
12
|
});
|
|
13
13
|
const state = {
|
|
14
|
-
finalHunk: diff.hunks.at(-1),
|
|
15
14
|
viewportStart: startingLine,
|
|
16
15
|
viewportEnd: startingLine + totalLines,
|
|
17
16
|
isWindowedHighlight: startingLine > 0 || totalLines < Infinity,
|
|
18
17
|
splitCount: iterationStart.splitCount,
|
|
19
18
|
unifiedCount: iterationStart.unifiedCount,
|
|
19
|
+
finalHunkIndex: diff.hunks.length - 1,
|
|
20
20
|
shouldBreak() {
|
|
21
21
|
if (!state.isWindowedHighlight) return false;
|
|
22
22
|
const breakUnified = state.unifiedCount >= startingLine + totalLines;
|
|
@@ -69,31 +69,24 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
69
69
|
hunkIndex,
|
|
70
70
|
collapsedContextThreshold
|
|
71
71
|
});
|
|
72
|
-
const trailingRegion =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
isPartial: diff.isPartial,
|
|
80
|
-
rangeSize: trailingRangeSize,
|
|
81
|
-
expandedHunks,
|
|
82
|
-
hunkIndex: diff.hunks.length,
|
|
83
|
-
collapsedContextThreshold
|
|
84
|
-
});
|
|
85
|
-
})();
|
|
72
|
+
const trailingRegion = hunkIndex === state.finalHunkIndex ? getTrailingExpandedRegion({
|
|
73
|
+
fileDiff: diff,
|
|
74
|
+
hunkIndex,
|
|
75
|
+
expandedHunks,
|
|
76
|
+
collapsedContextThreshold,
|
|
77
|
+
errorPrefix: "iterateOverDiff"
|
|
78
|
+
}) : void 0;
|
|
86
79
|
const expandedLineCount = leadingRegion.fromStart + leadingRegion.fromEnd;
|
|
87
80
|
function getTrailingCollapsedAfter(unifiedLineIndex$1, splitLineIndex$1) {
|
|
88
81
|
if (trailingRegion == null || trailingRegion.collapsedLines <= 0 || trailingRegion.fromStart + trailingRegion.fromEnd > 0) return 0;
|
|
89
82
|
if (diffStyle === "unified") return unifiedLineIndex$1 === hunk.unifiedLineStart + hunk.unifiedLineCount - 1 ? trailingRegion.collapsedLines : 0;
|
|
90
83
|
return splitLineIndex$1 === hunk.splitLineStart + hunk.splitLineCount - 1 ? trailingRegion.collapsedLines : 0;
|
|
91
84
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
85
|
+
let consumedCollapsed = leadingRegion.collapsedLines === 0;
|
|
86
|
+
function consumePendingCollapsed() {
|
|
87
|
+
if (consumedCollapsed) return 0;
|
|
88
|
+
consumedCollapsed = true;
|
|
89
|
+
return leadingRegion.collapsedLines;
|
|
97
90
|
}
|
|
98
91
|
if (!state.shouldSkip(expandedLineCount, expandedLineCount)) {
|
|
99
92
|
let unifiedLineIndex$1 = hunk.unifiedLineStart - leadingRegion.rangeSize;
|
|
@@ -102,81 +95,63 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
102
95
|
let additionLineIndex$1 = hunk.additionLineIndex - leadingRegion.rangeSize;
|
|
103
96
|
let deletionLineNumber$1 = hunk.deletionStart - leadingRegion.rangeSize;
|
|
104
97
|
let additionLineNumber$1 = hunk.additionStart - leadingRegion.rangeSize;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
unifiedLineIndex: unifiedLineIndex$1 + index,
|
|
129
|
-
splitLineIndex: splitLineIndex$1 + index,
|
|
130
|
-
lineIndex: additionLineIndex$1 + index,
|
|
131
|
-
lineNumber: additionLineNumber$1 + index,
|
|
132
|
-
noEOFCR: false
|
|
133
|
-
}
|
|
134
|
-
})) break hunkIterator;
|
|
135
|
-
} else state.incrementCounts(1, 1);
|
|
136
|
-
index++;
|
|
137
|
-
}
|
|
98
|
+
if (walkContextLines(state, leadingRegion.fromStart, diffStyle, (index) => {
|
|
99
|
+
return state.emit({
|
|
100
|
+
hunkIndex,
|
|
101
|
+
hunk,
|
|
102
|
+
collapsedBefore: 0,
|
|
103
|
+
collapsedAfter: 0,
|
|
104
|
+
type: "context-expanded",
|
|
105
|
+
deletionLine: {
|
|
106
|
+
lineNumber: deletionLineNumber$1 + index,
|
|
107
|
+
lineIndex: deletionLineIndex$1 + index,
|
|
108
|
+
noEOFCR: false,
|
|
109
|
+
unifiedLineIndex: unifiedLineIndex$1 + index,
|
|
110
|
+
splitLineIndex: splitLineIndex$1 + index
|
|
111
|
+
},
|
|
112
|
+
additionLine: {
|
|
113
|
+
unifiedLineIndex: unifiedLineIndex$1 + index,
|
|
114
|
+
splitLineIndex: splitLineIndex$1 + index,
|
|
115
|
+
lineIndex: additionLineIndex$1 + index,
|
|
116
|
+
lineNumber: additionLineNumber$1 + index,
|
|
117
|
+
noEOFCR: false
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
})) break hunkIterator;
|
|
138
121
|
unifiedLineIndex$1 = hunk.unifiedLineStart - leadingRegion.fromEnd;
|
|
139
122
|
splitLineIndex$1 = hunk.splitLineStart - leadingRegion.fromEnd;
|
|
140
123
|
deletionLineIndex$1 = hunk.deletionLineIndex - leadingRegion.fromEnd;
|
|
141
124
|
additionLineIndex$1 = hunk.additionLineIndex - leadingRegion.fromEnd;
|
|
142
125
|
deletionLineNumber$1 = hunk.deletionStart - leadingRegion.fromEnd;
|
|
143
126
|
additionLineNumber$1 = hunk.additionStart - leadingRegion.fromEnd;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
lineIndex: additionLineIndex$1 + index,
|
|
170
|
-
lineNumber: additionLineNumber$1 + index,
|
|
171
|
-
noEOFCR: false
|
|
172
|
-
}
|
|
173
|
-
})) break hunkIterator;
|
|
174
|
-
} else state.incrementCounts(1, 1);
|
|
175
|
-
index++;
|
|
176
|
-
}
|
|
127
|
+
if (walkContextLines(state, leadingRegion.fromEnd, diffStyle, (index) => {
|
|
128
|
+
return state.emit({
|
|
129
|
+
hunkIndex,
|
|
130
|
+
hunk,
|
|
131
|
+
collapsedBefore: consumePendingCollapsed(),
|
|
132
|
+
collapsedAfter: 0,
|
|
133
|
+
type: "context-expanded",
|
|
134
|
+
deletionLine: {
|
|
135
|
+
lineNumber: deletionLineNumber$1 + index,
|
|
136
|
+
lineIndex: deletionLineIndex$1 + index,
|
|
137
|
+
noEOFCR: false,
|
|
138
|
+
unifiedLineIndex: unifiedLineIndex$1 + index,
|
|
139
|
+
splitLineIndex: splitLineIndex$1 + index
|
|
140
|
+
},
|
|
141
|
+
additionLine: {
|
|
142
|
+
unifiedLineIndex: unifiedLineIndex$1 + index,
|
|
143
|
+
splitLineIndex: splitLineIndex$1 + index,
|
|
144
|
+
lineIndex: additionLineIndex$1 + index,
|
|
145
|
+
lineNumber: additionLineNumber$1 + index,
|
|
146
|
+
noEOFCR: false
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}, () => {
|
|
150
|
+
consumePendingCollapsed();
|
|
151
|
+
})) break hunkIterator;
|
|
177
152
|
} else {
|
|
178
153
|
state.incrementCounts(expandedLineCount, expandedLineCount);
|
|
179
|
-
|
|
154
|
+
consumePendingCollapsed();
|
|
180
155
|
}
|
|
181
156
|
let unifiedLineIndex = hunk.unifiedLineStart;
|
|
182
157
|
let splitLineIndex = hunk.splitLineStart;
|
|
@@ -190,45 +165,37 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
190
165
|
const isLastContent = content === lastContent;
|
|
191
166
|
if (content.type === "context") {
|
|
192
167
|
if (!state.shouldSkip(content.lines, content.lines)) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
lineIndex: additionLineIndex + index,
|
|
222
|
-
lineNumber: additionLineNumber + index,
|
|
223
|
-
noEOFCR: isLastLine && hunk.noEOFCRAdditions
|
|
224
|
-
}
|
|
225
|
-
})) break hunkIterator;
|
|
226
|
-
} else state.incrementCounts(1, 1);
|
|
227
|
-
index++;
|
|
228
|
-
}
|
|
168
|
+
if (walkContextLines(state, content.lines, diffStyle, (index) => {
|
|
169
|
+
const isLastLine = isLastContent && index === content.lines - 1;
|
|
170
|
+
const unifiedRowIndex = unifiedLineIndex + index;
|
|
171
|
+
const splitRowIndex = splitLineIndex + index;
|
|
172
|
+
return state.emit({
|
|
173
|
+
hunkIndex,
|
|
174
|
+
hunk,
|
|
175
|
+
collapsedBefore: consumePendingCollapsed(),
|
|
176
|
+
collapsedAfter: getTrailingCollapsedAfter(unifiedRowIndex, splitRowIndex),
|
|
177
|
+
type: "context",
|
|
178
|
+
deletionLine: {
|
|
179
|
+
lineNumber: deletionLineNumber + index,
|
|
180
|
+
lineIndex: deletionLineIndex + index,
|
|
181
|
+
noEOFCR: isLastLine && hunk.noEOFCRDeletions,
|
|
182
|
+
unifiedLineIndex: unifiedRowIndex,
|
|
183
|
+
splitLineIndex: splitRowIndex
|
|
184
|
+
},
|
|
185
|
+
additionLine: {
|
|
186
|
+
unifiedLineIndex: unifiedRowIndex,
|
|
187
|
+
splitLineIndex: splitRowIndex,
|
|
188
|
+
lineIndex: additionLineIndex + index,
|
|
189
|
+
lineNumber: additionLineNumber + index,
|
|
190
|
+
noEOFCR: isLastLine && hunk.noEOFCRAdditions
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}, () => {
|
|
194
|
+
consumePendingCollapsed();
|
|
195
|
+
})) break hunkIterator;
|
|
229
196
|
} else {
|
|
230
197
|
state.incrementCounts(content.lines, content.lines);
|
|
231
|
-
|
|
198
|
+
consumePendingCollapsed();
|
|
232
199
|
}
|
|
233
200
|
unifiedLineIndex += content.lines;
|
|
234
201
|
splitLineIndex += content.lines;
|
|
@@ -241,12 +208,13 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
241
208
|
const unifiedCount = content.deletions + content.additions;
|
|
242
209
|
if (!state.shouldSkip(unifiedCount, splitCount)) {
|
|
243
210
|
const iterationRanges = getChangeIterationRanges(state, content, diffStyle);
|
|
211
|
+
if ((iterationRanges[0]?.[0] ?? 0) > 0) consumePendingCollapsed();
|
|
244
212
|
for (const [rangeStart, rangeEnd] of iterationRanges) for (let index = rangeStart; index < rangeEnd; index++) {
|
|
245
213
|
const collapsedAfter = getTrailingCollapsedAfter(unifiedLineIndex + index, diffStyle === "unified" ? splitLineIndex + (index < content.deletions ? index : index - content.deletions) : splitLineIndex + index);
|
|
246
214
|
if (state.emit(getChangeLineData({
|
|
247
215
|
hunkIndex,
|
|
248
216
|
hunk,
|
|
249
|
-
collapsedBefore:
|
|
217
|
+
collapsedBefore: consumePendingCollapsed(),
|
|
250
218
|
collapsedAfter,
|
|
251
219
|
diffStyle,
|
|
252
220
|
index,
|
|
@@ -263,7 +231,7 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
263
231
|
}), true)) break hunkIterator;
|
|
264
232
|
}
|
|
265
233
|
}
|
|
266
|
-
|
|
234
|
+
consumePendingCollapsed();
|
|
267
235
|
state.incrementCounts(unifiedCount, splitCount);
|
|
268
236
|
unifiedLineIndex += unifiedCount;
|
|
269
237
|
splitLineIndex += splitCount;
|
|
@@ -276,41 +244,30 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
276
244
|
if (trailingRegion != null) {
|
|
277
245
|
const { collapsedLines, fromStart, fromEnd } = trailingRegion;
|
|
278
246
|
const len = fromStart + fromEnd;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
additionLine: {
|
|
304
|
-
unifiedLineIndex: unifiedLineIndex + index,
|
|
305
|
-
splitLineIndex: splitLineIndex + index,
|
|
306
|
-
lineIndex: additionLineIndex + index,
|
|
307
|
-
lineNumber: additionLineNumber + index,
|
|
308
|
-
noEOFCR: false
|
|
309
|
-
}
|
|
310
|
-
})) break hunkIterator;
|
|
311
|
-
} else state.incrementCounts(1, 1);
|
|
312
|
-
index++;
|
|
313
|
-
}
|
|
247
|
+
if (walkContextLines(state, len, diffStyle, (index) => {
|
|
248
|
+
const isLastLine = index === len - 1;
|
|
249
|
+
return state.emit({
|
|
250
|
+
hunkIndex: diff.hunks.length,
|
|
251
|
+
hunk: void 0,
|
|
252
|
+
collapsedBefore: 0,
|
|
253
|
+
collapsedAfter: isLastLine ? collapsedLines : 0,
|
|
254
|
+
type: "context-expanded",
|
|
255
|
+
deletionLine: {
|
|
256
|
+
lineNumber: deletionLineNumber + index,
|
|
257
|
+
lineIndex: deletionLineIndex + index,
|
|
258
|
+
noEOFCR: false,
|
|
259
|
+
unifiedLineIndex: unifiedLineIndex + index,
|
|
260
|
+
splitLineIndex: splitLineIndex + index
|
|
261
|
+
},
|
|
262
|
+
additionLine: {
|
|
263
|
+
unifiedLineIndex: unifiedLineIndex + index,
|
|
264
|
+
splitLineIndex: splitLineIndex + index,
|
|
265
|
+
lineIndex: additionLineIndex + index,
|
|
266
|
+
lineNumber: additionLineNumber + index,
|
|
267
|
+
noEOFCR: false
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}, void 0, () => state.shouldBreak())) break hunkIterator;
|
|
314
271
|
}
|
|
315
272
|
}
|
|
316
273
|
}
|
|
@@ -375,15 +332,14 @@ function getHunkPrefixCounts({ diff, expandedHunks, collapsedContextThreshold })
|
|
|
375
332
|
const leadingCount = leadingRegion.fromStart + leadingRegion.fromEnd;
|
|
376
333
|
splitCount += leadingCount + hunk.splitLineCount;
|
|
377
334
|
unifiedCount += leadingCount + hunk.unifiedLineCount;
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
335
|
+
const trailingRegion = index === finalHunkIndex ? getTrailingExpandedRegion({
|
|
336
|
+
fileDiff: diff,
|
|
337
|
+
hunkIndex: index,
|
|
338
|
+
expandedHunks,
|
|
339
|
+
collapsedContextThreshold,
|
|
340
|
+
errorPrefix: "iterateOverDiff"
|
|
341
|
+
}) : void 0;
|
|
342
|
+
if (trailingRegion != null) {
|
|
387
343
|
const trailingCount = trailingRegion.fromStart + trailingRegion.fromEnd;
|
|
388
344
|
splitCount += trailingCount;
|
|
389
345
|
unifiedCount += trailingCount;
|
|
@@ -395,7 +351,7 @@ function getHunkPrefixCounts({ diff, expandedHunks, collapsedContextThreshold })
|
|
|
395
351
|
}
|
|
396
352
|
return prefixCounts;
|
|
397
353
|
}
|
|
398
|
-
function
|
|
354
|
+
function getContextLineIterationBounds(state, count, diffStyle) {
|
|
399
355
|
if (!state.isWindowedHighlight || count <= 0) return [0, count];
|
|
400
356
|
const ranges = [];
|
|
401
357
|
function pushRange(currentCount) {
|
|
@@ -415,16 +371,25 @@ function getEqualLineIterationRange(state, count, diffStyle) {
|
|
|
415
371
|
}
|
|
416
372
|
return [start, end];
|
|
417
373
|
}
|
|
418
|
-
function
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
374
|
+
function walkContextLines(state, count, diffStyle, callback, onSkippedStart, shouldBreak) {
|
|
375
|
+
const [startIndex, endIndex] = getContextLineIterationBounds(state, count, diffStyle);
|
|
376
|
+
if (startIndex > 0) {
|
|
377
|
+
state.incrementCounts(startIndex, startIndex);
|
|
378
|
+
onSkippedStart?.();
|
|
379
|
+
}
|
|
380
|
+
let index = startIndex;
|
|
381
|
+
while (index < count) {
|
|
382
|
+
if (shouldBreak?.() === true) return true;
|
|
383
|
+
if (index >= endIndex) {
|
|
384
|
+
state.incrementCounts(count - index, count - index);
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
if (state.isInWindow(0, 0)) {
|
|
388
|
+
if (callback(index) === true) return true;
|
|
389
|
+
} else state.incrementCounts(1, 1);
|
|
390
|
+
index++;
|
|
391
|
+
}
|
|
392
|
+
return false;
|
|
428
393
|
}
|
|
429
394
|
function getChangeIterationRanges(state, content, diffStyle) {
|
|
430
395
|
if (!state.isWindowedHighlight) return [[0, diffStyle === "unified" ? content.deletions + content.additions : Math.max(content.deletions, content.additions)]];
|