@pierre/diffs 1.2.4 → 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.
@@ -15168,6 +15168,60 @@ function getExpandedRegion({ isPartial, rangeSize, expandedHunks, hunkIndex, col
15168
15168
  renderAll
15169
15169
  };
15170
15170
  }
15171
+ function hasTrailingContext(fileDiff) {
15172
+ const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];
15173
+ if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) {
15174
+ return false;
15175
+ }
15176
+ const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
15177
+ const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
15178
+ return additionRemaining > 0 || deletionRemaining > 0;
15179
+ }
15180
+ function getTrailingContextRangeSize({ fileDiff, errorPrefix }) {
15181
+ const lastHunk = fileDiff.hunks[fileDiff.hunks.length - 1];
15182
+ if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) {
15183
+ return 0;
15184
+ }
15185
+ const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
15186
+ const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
15187
+ if (additionRemaining <= 0 && deletionRemaining <= 0) {
15188
+ return 0;
15189
+ }
15190
+ if (additionRemaining !== deletionRemaining) {
15191
+ throw new Error(`${errorPrefix}: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${fileDiff.name}`);
15192
+ }
15193
+ return Math.min(additionRemaining, deletionRemaining);
15194
+ }
15195
+ function getTrailingExpandedRegion({ fileDiff, hunkIndex, expandedHunks, collapsedContextThreshold, errorPrefix }) {
15196
+ if (hunkIndex !== fileDiff.hunks.length - 1) {
15197
+ return undefined;
15198
+ }
15199
+ const trailingRangeSize = getTrailingContextRangeSize({
15200
+ fileDiff,
15201
+ errorPrefix
15202
+ });
15203
+ if (trailingRangeSize <= 0) {
15204
+ return undefined;
15205
+ }
15206
+ if (expandedHunks === true || trailingRangeSize <= collapsedContextThreshold) {
15207
+ return {
15208
+ fromStart: trailingRangeSize,
15209
+ fromEnd: 0,
15210
+ rangeSize: trailingRangeSize,
15211
+ collapsedLines: 0,
15212
+ renderAll: true
15213
+ };
15214
+ }
15215
+ const region = expandedHunks?.get(fileDiff.hunks.length);
15216
+ const fromStart = Math.min(Math.max(region?.fromStart ?? 0, 0), trailingRangeSize);
15217
+ return {
15218
+ fromStart,
15219
+ fromEnd: 0,
15220
+ rangeSize: trailingRangeSize,
15221
+ collapsedLines: trailingRangeSize - fromStart,
15222
+ renderAll: fromStart >= trailingRangeSize
15223
+ };
15224
+ }
15171
15225
  function getHunkSeparatorHeight({ type, metrics }) {
15172
15226
  return metrics.hunkSeparatorHeight ?? getDefaultHunkSeparatorHeight(type);
15173
15227
  }
@@ -15242,12 +15296,12 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15242
15296
  collapsedContextThreshold
15243
15297
  });
15244
15298
  const state = {
15245
- finalHunk: diff.hunks.at(-1),
15246
15299
  viewportStart: startingLine,
15247
15300
  viewportEnd: startingLine + totalLines,
15248
15301
  isWindowedHighlight: startingLine > 0 || totalLines < Infinity,
15249
15302
  splitCount: iterationStart.splitCount,
15250
15303
  unifiedCount: iterationStart.unifiedCount,
15304
+ finalHunkIndex: diff.hunks.length - 1,
15251
15305
  shouldBreak() {
15252
15306
  if (!state.isWindowedHighlight) {
15253
15307
  return false;
@@ -15332,24 +15386,13 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15332
15386
  hunkIndex,
15333
15387
  collapsedContextThreshold
15334
15388
  });
15335
- const trailingRegion = (() => {
15336
- if (hunk !== state.finalHunk || !hasFinalCollapsedHunk(diff)) {
15337
- return undefined;
15338
- }
15339
- const additionRemaining = diff.additionLines.length - (hunk.additionLineIndex + hunk.additionCount);
15340
- const deletionRemaining = diff.deletionLines.length - (hunk.deletionLineIndex + hunk.deletionCount);
15341
- if (additionRemaining !== deletionRemaining) {
15342
- throw new Error(`iterateOverDiff: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${diff.name}`);
15343
- }
15344
- const trailingRangeSize = Math.min(additionRemaining, deletionRemaining);
15345
- return getExpandedRegion({
15346
- isPartial: diff.isPartial,
15347
- rangeSize: trailingRangeSize,
15348
- expandedHunks,
15349
- hunkIndex: diff.hunks.length,
15350
- collapsedContextThreshold
15351
- });
15352
- })();
15389
+ const trailingRegion = hunkIndex === state.finalHunkIndex ? getTrailingExpandedRegion({
15390
+ fileDiff: diff,
15391
+ hunkIndex,
15392
+ expandedHunks,
15393
+ collapsedContextThreshold,
15394
+ errorPrefix: "iterateOverDiff"
15395
+ }) : undefined;
15353
15396
  const expandedLineCount = leadingRegion.fromStart + leadingRegion.fromEnd;
15354
15397
  function getTrailingCollapsedAfter(unifiedLineIndex$1, splitLineIndex$1) {
15355
15398
  if (trailingRegion == null || trailingRegion.collapsedLines <= 0 || trailingRegion.fromStart + trailingRegion.fromEnd > 0) {
@@ -15360,13 +15403,13 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15360
15403
  }
15361
15404
  return splitLineIndex$1 === hunk.splitLineStart + hunk.splitLineCount - 1 ? trailingRegion.collapsedLines : 0;
15362
15405
  }
15363
- function getPendingCollapsed() {
15364
- if (leadingRegion.collapsedLines === 0) {
15406
+ let consumedCollapsed = leadingRegion.collapsedLines === 0;
15407
+ function consumePendingCollapsed() {
15408
+ if (consumedCollapsed) {
15365
15409
  return 0;
15366
15410
  }
15367
- const value = leadingRegion.collapsedLines;
15368
- leadingRegion.collapsedLines = 0;
15369
- return value;
15411
+ consumedCollapsed = true;
15412
+ return leadingRegion.collapsedLines;
15370
15413
  }
15371
15414
  if (!state.shouldSkip(expandedLineCount, expandedLineCount)) {
15372
15415
  let unifiedLineIndex$1 = hunk.unifiedLineStart - leadingRegion.rangeSize;
@@ -15375,44 +15418,30 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15375
15418
  let additionLineIndex$1 = hunk.additionLineIndex - leadingRegion.rangeSize;
15376
15419
  let deletionLineNumber$1 = hunk.deletionStart - leadingRegion.rangeSize;
15377
15420
  let additionLineNumber$1 = hunk.additionStart - leadingRegion.rangeSize;
15378
- const [startIndex, endIndex] = getEqualLineIterationRange(state, leadingRegion.fromStart, diffStyle);
15379
- if (startIndex > 0) {
15380
- state.incrementCounts(startIndex, startIndex);
15381
- }
15382
- let index = startIndex;
15383
- while (index < leadingRegion.fromStart) {
15384
- if (index >= endIndex) {
15385
- state.incrementCounts(leadingRegion.fromStart - index, leadingRegion.fromStart - index);
15386
- break;
15387
- }
15388
- if (state.isInWindow(0, 0)) {
15389
- if (state.emit({
15390
- hunkIndex,
15391
- hunk,
15392
- collapsedBefore: 0,
15393
- collapsedAfter: 0,
15394
- type: "context-expanded",
15395
- deletionLine: {
15396
- lineNumber: deletionLineNumber$1 + index,
15397
- lineIndex: deletionLineIndex$1 + index,
15398
- noEOFCR: false,
15399
- unifiedLineIndex: unifiedLineIndex$1 + index,
15400
- splitLineIndex: splitLineIndex$1 + index
15401
- },
15402
- additionLine: {
15403
- unifiedLineIndex: unifiedLineIndex$1 + index,
15404
- splitLineIndex: splitLineIndex$1 + index,
15405
- lineIndex: additionLineIndex$1 + index,
15406
- lineNumber: additionLineNumber$1 + index,
15407
- noEOFCR: false
15408
- }
15409
- })) {
15410
- break hunkIterator;
15421
+ if (walkContextLines(state, leadingRegion.fromStart, diffStyle, (index) => {
15422
+ return state.emit({
15423
+ hunkIndex,
15424
+ hunk,
15425
+ collapsedBefore: 0,
15426
+ collapsedAfter: 0,
15427
+ type: "context-expanded",
15428
+ deletionLine: {
15429
+ lineNumber: deletionLineNumber$1 + index,
15430
+ lineIndex: deletionLineIndex$1 + index,
15431
+ noEOFCR: false,
15432
+ unifiedLineIndex: unifiedLineIndex$1 + index,
15433
+ splitLineIndex: splitLineIndex$1 + index
15434
+ },
15435
+ additionLine: {
15436
+ unifiedLineIndex: unifiedLineIndex$1 + index,
15437
+ splitLineIndex: splitLineIndex$1 + index,
15438
+ lineIndex: additionLineIndex$1 + index,
15439
+ lineNumber: additionLineNumber$1 + index,
15440
+ noEOFCR: false
15411
15441
  }
15412
- } else {
15413
- state.incrementCounts(1, 1);
15414
- }
15415
- index++;
15442
+ });
15443
+ })) {
15444
+ break hunkIterator;
15416
15445
  }
15417
15446
  unifiedLineIndex$1 = hunk.unifiedLineStart - leadingRegion.fromEnd;
15418
15447
  splitLineIndex$1 = hunk.splitLineStart - leadingRegion.fromEnd;
@@ -15420,48 +15449,36 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15420
15449
  additionLineIndex$1 = hunk.additionLineIndex - leadingRegion.fromEnd;
15421
15450
  deletionLineNumber$1 = hunk.deletionStart - leadingRegion.fromEnd;
15422
15451
  additionLineNumber$1 = hunk.additionStart - leadingRegion.fromEnd;
15423
- const [fromEndStartIndex, fromEndEndIndex] = getEqualLineIterationRange(state, leadingRegion.fromEnd, diffStyle);
15424
- if (fromEndStartIndex > 0) {
15425
- state.incrementCounts(fromEndStartIndex, fromEndStartIndex);
15426
- }
15427
- index = fromEndStartIndex;
15428
- while (index < leadingRegion.fromEnd) {
15429
- if (index >= fromEndEndIndex) {
15430
- state.incrementCounts(leadingRegion.fromEnd - index, leadingRegion.fromEnd - index);
15431
- break;
15432
- }
15433
- if (state.isInWindow(0, 0)) {
15434
- if (state.emit({
15435
- hunkIndex,
15436
- hunk,
15437
- collapsedBefore: getPendingCollapsed(),
15438
- collapsedAfter: 0,
15439
- type: "context-expanded",
15440
- deletionLine: {
15441
- lineNumber: deletionLineNumber$1 + index,
15442
- lineIndex: deletionLineIndex$1 + index,
15443
- noEOFCR: false,
15444
- unifiedLineIndex: unifiedLineIndex$1 + index,
15445
- splitLineIndex: splitLineIndex$1 + index
15446
- },
15447
- additionLine: {
15448
- unifiedLineIndex: unifiedLineIndex$1 + index,
15449
- splitLineIndex: splitLineIndex$1 + index,
15450
- lineIndex: additionLineIndex$1 + index,
15451
- lineNumber: additionLineNumber$1 + index,
15452
- noEOFCR: false
15453
- }
15454
- })) {
15455
- break hunkIterator;
15452
+ if (walkContextLines(state, leadingRegion.fromEnd, diffStyle, (index) => {
15453
+ return state.emit({
15454
+ hunkIndex,
15455
+ hunk,
15456
+ collapsedBefore: consumePendingCollapsed(),
15457
+ collapsedAfter: 0,
15458
+ type: "context-expanded",
15459
+ deletionLine: {
15460
+ lineNumber: deletionLineNumber$1 + index,
15461
+ lineIndex: deletionLineIndex$1 + index,
15462
+ noEOFCR: false,
15463
+ unifiedLineIndex: unifiedLineIndex$1 + index,
15464
+ splitLineIndex: splitLineIndex$1 + index
15465
+ },
15466
+ additionLine: {
15467
+ unifiedLineIndex: unifiedLineIndex$1 + index,
15468
+ splitLineIndex: splitLineIndex$1 + index,
15469
+ lineIndex: additionLineIndex$1 + index,
15470
+ lineNumber: additionLineNumber$1 + index,
15471
+ noEOFCR: false
15456
15472
  }
15457
- } else {
15458
- state.incrementCounts(1, 1);
15459
- }
15460
- index++;
15473
+ });
15474
+ }, () => {
15475
+ consumePendingCollapsed();
15476
+ })) {
15477
+ break hunkIterator;
15461
15478
  }
15462
15479
  } else {
15463
15480
  state.incrementCounts(expandedLineCount, expandedLineCount);
15464
- getPendingCollapsed();
15481
+ consumePendingCollapsed();
15465
15482
  }
15466
15483
  let unifiedLineIndex = hunk.unifiedLineStart;
15467
15484
  let splitLineIndex = hunk.splitLineStart;
@@ -15477,51 +15494,39 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15477
15494
  const isLastContent = content === lastContent;
15478
15495
  if (content.type === "context") {
15479
15496
  if (!state.shouldSkip(content.lines, content.lines)) {
15480
- const [startIndex, endIndex] = getEqualLineIterationRange(state, content.lines, diffStyle);
15481
- if (startIndex > 0) {
15482
- state.incrementCounts(startIndex, startIndex);
15483
- }
15484
- let index = startIndex;
15485
- while (index < content.lines) {
15486
- if (index >= endIndex) {
15487
- state.incrementCounts(content.lines - index, content.lines - index);
15488
- break;
15489
- }
15490
- if (state.isInWindow(0, 0)) {
15491
- const isLastLine = isLastContent && index === content.lines - 1;
15492
- const unifiedRowIndex = unifiedLineIndex + index;
15493
- const splitRowIndex = splitLineIndex + index;
15494
- if (state.emit({
15495
- hunkIndex,
15496
- hunk,
15497
- collapsedBefore: getPendingCollapsed(),
15498
- collapsedAfter: getTrailingCollapsedAfter(unifiedRowIndex, splitRowIndex),
15499
- type: "context",
15500
- deletionLine: {
15501
- lineNumber: deletionLineNumber + index,
15502
- lineIndex: deletionLineIndex + index,
15503
- noEOFCR: isLastLine && hunk.noEOFCRDeletions,
15504
- unifiedLineIndex: unifiedRowIndex,
15505
- splitLineIndex: splitRowIndex
15506
- },
15507
- additionLine: {
15508
- unifiedLineIndex: unifiedRowIndex,
15509
- splitLineIndex: splitRowIndex,
15510
- lineIndex: additionLineIndex + index,
15511
- lineNumber: additionLineNumber + index,
15512
- noEOFCR: isLastLine && hunk.noEOFCRAdditions
15513
- }
15514
- })) {
15515
- break hunkIterator;
15497
+ if (walkContextLines(state, content.lines, diffStyle, (index) => {
15498
+ const isLastLine = isLastContent && index === content.lines - 1;
15499
+ const unifiedRowIndex = unifiedLineIndex + index;
15500
+ const splitRowIndex = splitLineIndex + index;
15501
+ return state.emit({
15502
+ hunkIndex,
15503
+ hunk,
15504
+ collapsedBefore: consumePendingCollapsed(),
15505
+ collapsedAfter: getTrailingCollapsedAfter(unifiedRowIndex, splitRowIndex),
15506
+ type: "context",
15507
+ deletionLine: {
15508
+ lineNumber: deletionLineNumber + index,
15509
+ lineIndex: deletionLineIndex + index,
15510
+ noEOFCR: isLastLine && hunk.noEOFCRDeletions,
15511
+ unifiedLineIndex: unifiedRowIndex,
15512
+ splitLineIndex: splitRowIndex
15513
+ },
15514
+ additionLine: {
15515
+ unifiedLineIndex: unifiedRowIndex,
15516
+ splitLineIndex: splitRowIndex,
15517
+ lineIndex: additionLineIndex + index,
15518
+ lineNumber: additionLineNumber + index,
15519
+ noEOFCR: isLastLine && hunk.noEOFCRAdditions
15516
15520
  }
15517
- } else {
15518
- state.incrementCounts(1, 1);
15519
- }
15520
- index++;
15521
+ });
15522
+ }, () => {
15523
+ consumePendingCollapsed();
15524
+ })) {
15525
+ break hunkIterator;
15521
15526
  }
15522
15527
  } else {
15523
15528
  state.incrementCounts(content.lines, content.lines);
15524
- getPendingCollapsed();
15529
+ consumePendingCollapsed();
15525
15530
  }
15526
15531
  unifiedLineIndex += content.lines;
15527
15532
  splitLineIndex += content.lines;
@@ -15535,6 +15540,10 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15535
15540
  const shouldSkipChange = state.shouldSkip(unifiedCount, splitCount);
15536
15541
  if (!shouldSkipChange) {
15537
15542
  const iterationRanges = getChangeIterationRanges(state, content, diffStyle);
15543
+ const firstRangeStart = iterationRanges[0]?.[0] ?? 0;
15544
+ if (firstRangeStart > 0) {
15545
+ consumePendingCollapsed();
15546
+ }
15538
15547
  for (const [rangeStart, rangeEnd] of iterationRanges) {
15539
15548
  for (let index = rangeStart; index < rangeEnd; index++) {
15540
15549
  const unifiedRowIndex = unifiedLineIndex + index;
@@ -15543,7 +15552,7 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15543
15552
  if (state.emit(getChangeLineData({
15544
15553
  hunkIndex,
15545
15554
  hunk,
15546
- collapsedBefore: getPendingCollapsed(),
15555
+ collapsedBefore: consumePendingCollapsed(),
15547
15556
  collapsedAfter,
15548
15557
  diffStyle,
15549
15558
  index,
@@ -15563,7 +15572,7 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15563
15572
  }
15564
15573
  }
15565
15574
  }
15566
- getPendingCollapsed();
15575
+ consumePendingCollapsed();
15567
15576
  state.incrementCounts(unifiedCount, splitCount);
15568
15577
  unifiedLineIndex += unifiedCount;
15569
15578
  splitLineIndex += splitCount;
@@ -15576,48 +15585,31 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
15576
15585
  if (trailingRegion != null) {
15577
15586
  const { collapsedLines, fromStart, fromEnd } = trailingRegion;
15578
15587
  const len = fromStart + fromEnd;
15579
- const [startIndex, endIndex] = getEqualLineIterationRange(state, len, diffStyle);
15580
- if (startIndex > 0) {
15581
- state.incrementCounts(startIndex, startIndex);
15582
- }
15583
- let index = startIndex;
15584
- while (index < len) {
15585
- if (state.shouldBreak()) {
15586
- break hunkIterator;
15587
- }
15588
- if (index >= endIndex) {
15589
- state.incrementCounts(len - index, len - index);
15590
- break;
15591
- }
15592
- if (state.isInWindow(0, 0)) {
15593
- const isLastLine = index === len - 1;
15594
- if (state.emit({
15595
- hunkIndex: diff.hunks.length,
15596
- hunk: undefined,
15597
- collapsedBefore: 0,
15598
- collapsedAfter: isLastLine ? collapsedLines : 0,
15599
- type: "context-expanded",
15600
- deletionLine: {
15601
- lineNumber: deletionLineNumber + index,
15602
- lineIndex: deletionLineIndex + index,
15603
- noEOFCR: false,
15604
- unifiedLineIndex: unifiedLineIndex + index,
15605
- splitLineIndex: splitLineIndex + index
15606
- },
15607
- additionLine: {
15608
- unifiedLineIndex: unifiedLineIndex + index,
15609
- splitLineIndex: splitLineIndex + index,
15610
- lineIndex: additionLineIndex + index,
15611
- lineNumber: additionLineNumber + index,
15612
- noEOFCR: false
15613
- }
15614
- })) {
15615
- break hunkIterator;
15588
+ if (walkContextLines(state, len, diffStyle, (index) => {
15589
+ const isLastLine = index === len - 1;
15590
+ return state.emit({
15591
+ hunkIndex: diff.hunks.length,
15592
+ hunk: undefined,
15593
+ collapsedBefore: 0,
15594
+ collapsedAfter: isLastLine ? collapsedLines : 0,
15595
+ type: "context-expanded",
15596
+ deletionLine: {
15597
+ lineNumber: deletionLineNumber + index,
15598
+ lineIndex: deletionLineIndex + index,
15599
+ noEOFCR: false,
15600
+ unifiedLineIndex: unifiedLineIndex + index,
15601
+ splitLineIndex: splitLineIndex + index
15602
+ },
15603
+ additionLine: {
15604
+ unifiedLineIndex: unifiedLineIndex + index,
15605
+ splitLineIndex: splitLineIndex + index,
15606
+ lineIndex: additionLineIndex + index,
15607
+ lineNumber: additionLineNumber + index,
15608
+ noEOFCR: false
15616
15609
  }
15617
- } else {
15618
- state.incrementCounts(1, 1);
15619
- }
15620
- index++;
15610
+ });
15611
+ }, undefined, () => state.shouldBreak())) {
15612
+ break hunkIterator;
15621
15613
  }
15622
15614
  }
15623
15615
  }
@@ -15696,15 +15688,14 @@ function getHunkPrefixCounts({ diff, expandedHunks, collapsedContextThreshold })
15696
15688
  const leadingCount = leadingRegion.fromStart + leadingRegion.fromEnd;
15697
15689
  splitCount += leadingCount + hunk.splitLineCount;
15698
15690
  unifiedCount += leadingCount + hunk.unifiedLineCount;
15699
- if (index === finalHunkIndex && hasFinalCollapsedHunk(diff)) {
15700
- const trailingRangeSize = getTrailingRangeSize(diff, hunk);
15701
- const trailingRegion = getExpandedRegion({
15702
- isPartial: diff.isPartial,
15703
- rangeSize: trailingRangeSize,
15704
- expandedHunks,
15705
- hunkIndex: diff.hunks.length,
15706
- collapsedContextThreshold
15707
- });
15691
+ const trailingRegion = index === finalHunkIndex ? getTrailingExpandedRegion({
15692
+ fileDiff: diff,
15693
+ hunkIndex: index,
15694
+ expandedHunks,
15695
+ collapsedContextThreshold,
15696
+ errorPrefix: "iterateOverDiff"
15697
+ }) : undefined;
15698
+ if (trailingRegion != null) {
15708
15699
  const trailingCount = trailingRegion.fromStart + trailingRegion.fromEnd;
15709
15700
  splitCount += trailingCount;
15710
15701
  unifiedCount += trailingCount;
@@ -15716,7 +15707,7 @@ function getHunkPrefixCounts({ diff, expandedHunks, collapsedContextThreshold })
15716
15707
  }
15717
15708
  return prefixCounts;
15718
15709
  }
15719
- function getEqualLineIterationRange(state, count, diffStyle) {
15710
+ function getContextLineIterationBounds(state, count, diffStyle) {
15720
15711
  if (!state.isWindowedHighlight || count <= 0) {
15721
15712
  return [0, count];
15722
15713
  }
@@ -15746,20 +15737,31 @@ function getEqualLineIterationRange(state, count, diffStyle) {
15746
15737
  }
15747
15738
  return [start, end];
15748
15739
  }
15749
- function getTrailingRangeSize(diff, hunk) {
15750
- const additionRemaining = diff.additionLines.length - (hunk.additionLineIndex + hunk.additionCount);
15751
- const deletionRemaining = diff.deletionLines.length - (hunk.deletionLineIndex + hunk.deletionCount);
15752
- if (additionRemaining !== deletionRemaining) {
15753
- throw new Error(`iterateOverDiff: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${diff.name}`);
15740
+ function walkContextLines(state, count, diffStyle, callback, onSkippedStart, shouldBreak) {
15741
+ const [startIndex, endIndex] = getContextLineIterationBounds(state, count, diffStyle);
15742
+ if (startIndex > 0) {
15743
+ state.incrementCounts(startIndex, startIndex);
15744
+ onSkippedStart?.();
15754
15745
  }
15755
- return Math.min(additionRemaining, deletionRemaining);
15756
- }
15757
- function hasFinalCollapsedHunk(diff) {
15758
- const lastHunk = diff.hunks.at(-1);
15759
- if (lastHunk == null || diff.isPartial || diff.additionLines.length === 0 || diff.deletionLines.length === 0) {
15760
- return false;
15746
+ let index = startIndex;
15747
+ while (index < count) {
15748
+ if (shouldBreak?.() === true) {
15749
+ return true;
15750
+ }
15751
+ if (index >= endIndex) {
15752
+ state.incrementCounts(count - index, count - index);
15753
+ break;
15754
+ }
15755
+ if (state.isInWindow(0, 0)) {
15756
+ if (callback(index) === true) {
15757
+ return true;
15758
+ }
15759
+ } else {
15760
+ state.incrementCounts(1, 1);
15761
+ }
15762
+ index++;
15761
15763
  }
15762
- return lastHunk.additionLineIndex + lastHunk.additionCount < diff.additionLines.length || lastHunk.deletionLineIndex + lastHunk.deletionCount < diff.deletionLines.length;
15764
+ return false;
15763
15765
  }
15764
15766
  function getChangeIterationRanges(state, content, diffStyle) {
15765
15767
  if (!state.isWindowedHighlight) {