@pierre/diffs 1.6.0-beta.1 → 1.6.0

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 (151) hide show
  1. package/dist/components/CodeView.d.ts +3 -2
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +18 -14
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +31 -9
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +165 -84
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +32 -9
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +213 -124
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts +14 -4
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +35 -16
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +3 -2
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +28 -20
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +3 -2
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +31 -24
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/constants.d.ts +2 -1
  26. package/dist/constants.d.ts.map +1 -1
  27. package/dist/constants.js +2 -1
  28. package/dist/constants.js.map +1 -1
  29. package/dist/editor/platform.d.ts +1 -1
  30. package/dist/editor/platform.js +5 -4
  31. package/dist/editor/platform.js.map +1 -1
  32. package/dist/editor/selection.d.ts +2 -2
  33. package/dist/editor/selection.d.ts.map +1 -1
  34. package/dist/editor/selection.js +31 -6
  35. package/dist/editor/selection.js.map +1 -1
  36. package/dist/highlighter/shared_highlighter.d.ts +2 -1
  37. package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
  38. package/dist/highlighter/shared_highlighter.js +2 -2
  39. package/dist/highlighter/shared_highlighter.js.map +1 -1
  40. package/dist/index.d.ts +10 -5
  41. package/dist/index.js +8 -3
  42. package/dist/react/CodeView.d.ts +4 -3
  43. package/dist/react/CodeView.d.ts.map +1 -1
  44. package/dist/react/CodeView.js +48 -39
  45. package/dist/react/CodeView.js.map +1 -1
  46. package/dist/react/File.js +3 -3
  47. package/dist/react/File.js.map +1 -1
  48. package/dist/react/FileDiff.js +3 -3
  49. package/dist/react/FileDiff.js.map +1 -1
  50. package/dist/react/MultiFileDiff.js +2 -2
  51. package/dist/react/MultiFileDiff.js.map +1 -1
  52. package/dist/react/PatchDiff.js +3 -3
  53. package/dist/react/PatchDiff.js.map +1 -1
  54. package/dist/react/UnresolvedFile.js +2 -2
  55. package/dist/react/UnresolvedFile.js.map +1 -1
  56. package/dist/react/index.d.ts +2 -2
  57. package/dist/react/types.d.ts +4 -2
  58. package/dist/react/types.d.ts.map +1 -1
  59. package/dist/react/utils/renderDiffChildren.js +1 -1
  60. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  61. package/dist/react/utils/renderFileChildren.js +1 -1
  62. package/dist/react/utils/renderFileChildren.js.map +1 -1
  63. package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
  64. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  65. package/dist/react/utils/useFileDiffInstance.js +29 -24
  66. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  67. package/dist/react/utils/useFileInstance.d.ts +2 -0
  68. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  69. package/dist/react/utils/useFileInstance.js +38 -28
  70. package/dist/react/utils/useFileInstance.js.map +1 -1
  71. package/dist/react/utils/useForceUpdate.d.ts +5 -0
  72. package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
  73. package/dist/react/utils/useForceUpdate.js +27 -0
  74. package/dist/react/utils/useForceUpdate.js.map +1 -0
  75. package/dist/react/utils/useNextRenderData.d.ts +9 -0
  76. package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
  77. package/dist/react/utils/useNextRenderData.js +9 -0
  78. package/dist/react/utils/useNextRenderData.js.map +1 -0
  79. package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
  80. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  81. package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
  82. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  83. package/dist/renderers/DiffHunksRenderer.d.ts +2 -1
  84. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  85. package/dist/renderers/DiffHunksRenderer.js +62 -32
  86. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  87. package/dist/renderers/FileRenderer.d.ts +4 -1
  88. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  89. package/dist/renderers/FileRenderer.js +55 -30
  90. package/dist/renderers/FileRenderer.js.map +1 -1
  91. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  92. package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
  93. package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
  94. package/dist/ssr/FileDiffReact.js +1 -1
  95. package/dist/types.d.ts +10 -0
  96. package/dist/types.d.ts.map +1 -1
  97. package/dist/utils/canUseWASM.d.ts +13 -0
  98. package/dist/utils/canUseWASM.d.ts.map +1 -0
  99. package/dist/utils/canUseWASM.js +59 -0
  100. package/dist/utils/canUseWASM.js.map +1 -0
  101. package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
  102. package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
  103. package/dist/utils/getCodeViewItemRenderData.js +19 -0
  104. package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
  105. package/dist/utils/hastToHtml.d.ts +2 -2
  106. package/dist/utils/hastToHtml.js +2 -2
  107. package/dist/utils/hastToHtml.js.map +1 -1
  108. package/dist/utils/hydratePartialDiff.js +4 -0
  109. package/dist/utils/hydratePartialDiff.js.map +1 -1
  110. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  111. package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
  112. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  113. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  114. package/dist/utils/parsePatchFiles.js +24 -4
  115. package/dist/utils/parsePatchFiles.js.map +1 -1
  116. package/dist/utils/renderTokenLines.d.ts +6 -1
  117. package/dist/utils/renderTokenLines.d.ts.map +1 -1
  118. package/dist/utils/renderTokenLines.js +4 -0
  119. package/dist/utils/renderTokenLines.js.map +1 -1
  120. package/dist/utils/resolveRegion.js +20 -10
  121. package/dist/utils/resolveRegion.js.map +1 -1
  122. package/dist/utils/tokenStyle.d.ts +5 -1
  123. package/dist/utils/tokenStyle.d.ts.map +1 -1
  124. package/dist/utils/tokenStyle.js +5 -1
  125. package/dist/utils/tokenStyle.js.map +1 -1
  126. package/dist/utils/tokensToHtml.d.ts +5 -2
  127. package/dist/utils/tokensToHtml.d.ts.map +1 -1
  128. package/dist/utils/tokensToHtml.js +5 -2
  129. package/dist/utils/tokensToHtml.js.map +1 -1
  130. package/dist/utils/updateDiffHunks.d.ts +2 -2
  131. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  132. package/dist/utils/updateDiffHunks.js +7 -3
  133. package/dist/utils/updateDiffHunks.js.map +1 -1
  134. package/dist/worker/WorkerPoolManager.d.ts +12 -0
  135. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  136. package/dist/worker/WorkerPoolManager.js +99 -21
  137. package/dist/worker/WorkerPoolManager.js.map +1 -1
  138. package/dist/worker/{highlights-sAHlxqlf.js → highlights-CpZm9DAR.js} +2 -2
  139. package/dist/worker/{highlights-sAHlxqlf.js.map → highlights-CpZm9DAR.js.map} +1 -1
  140. package/dist/worker/{shiki-Bx2JpdqZ.js → shiki-Ci4cdHsM.js} +2 -2
  141. package/dist/worker/{shiki-Bx2JpdqZ.js.map → shiki-Ci4cdHsM.js.map} +1 -1
  142. package/dist/worker/{stream-tokenizer-YZ6M1qSx.js → stream-tokenizer-DK9xp5M5.js} +8 -5
  143. package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
  144. package/dist/worker/types.d.ts +11 -0
  145. package/dist/worker/types.d.ts.map +1 -1
  146. package/dist/worker/worker-portable.js +2 -2
  147. package/dist/worker/worker-portable.js.map +1 -1
  148. package/dist/worker/worker.js +12 -3
  149. package/dist/worker/worker.js.map +1 -1
  150. package/package.json +28 -30
  151. package/dist/worker/stream-tokenizer-YZ6M1qSx.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { CUSTOM_HEADER_SLOT_ID, DEFAULT_THEMES, EMPTY_RENDER_RANGE, HEADER_FILENAME_SUFFIX_SLOT_ID, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID } from "../constants.js";
1
+ import { CUSTOM_HEADER_SLOT_ID, DEFAULT_THEMES, EMPTY_LINE_ANNOTATIONS, EMPTY_RENDER_RANGE, HEADER_FILENAME_SUFFIX_SLOT_ID, HEADER_METADATA_SLOT_ID, HEADER_PREFIX_SLOT_ID } from "../constants.js";
2
2
  import { HighlighterDisposedError } from "../highlighter/highlighterType.js";
3
3
  import { getThemes } from "../utils/getThemes.js";
4
4
  import { getHighlighterIfLoaded, getSharedHighlighter } from "../highlighter/shared_highlighter.js";
@@ -69,16 +69,16 @@ function shouldResetUndoState(prevDiff, nextDiff) {
69
69
  function areLinesEqual(first, second) {
70
70
  return first.length === second.length && first.every((line, index) => line === second[index]);
71
71
  }
72
- function canRestoreDiffSession(snapshot, externalDiff) {
72
+ function canRestoreDiffSession(snapshot, inputDiff) {
73
73
  const { oldFile } = snapshot;
74
- if (oldFile == null) return externalDiff.type === "new";
75
- return externalDiff.type !== "new" && oldFile.name === (externalDiff.prevName ?? externalDiff.name) && areLinesEqual(oldFile.lines, externalDiff.deletionLines);
74
+ if (oldFile == null) return inputDiff.type === "new";
75
+ return inputDiff.type !== "new" && oldFile.name === (inputDiff.prevName ?? inputDiff.name) && areLinesEqual(oldFile.lines, inputDiff.deletionLines);
76
76
  }
77
77
  let instanceId = -1;
78
78
  var FileDiff = class {
79
79
  options;
80
80
  workerManager;
81
- isContainerManaged;
81
+ requestOwnerRender;
82
82
  static LoadedCustomComponent = true;
83
83
  __id = `file-diff:${++instanceId}`;
84
84
  type = "file-diff";
@@ -109,13 +109,17 @@ var FileDiff = class {
109
109
  scrollSyncManager;
110
110
  interactionManager;
111
111
  annotationCache = /* @__PURE__ */ new Map();
112
- lineAnnotations = [];
112
+ get lineAnnotations() {
113
+ return this.renderedData?.lineAnnotations ?? EMPTY_LINE_ANNOTATIONS;
114
+ }
113
115
  managersDirty = false;
114
116
  deletionFile;
115
117
  additionFile;
116
118
  fileDiff;
117
119
  editSession;
118
- renderedDiff;
120
+ renderedData;
121
+ pendingData;
122
+ forceRenderOverride;
119
123
  renderRange;
120
124
  pendingFiles;
121
125
  appliedPreAttributes;
@@ -132,10 +136,10 @@ var FileDiff = class {
132
136
  lineStateRefreshPending = false;
133
137
  deferredSelectedLines;
134
138
  deferredEditorActiveLine;
135
- constructor(options = { theme: DEFAULT_THEMES }, workerManager, isContainerManaged = false) {
139
+ constructor(options = { theme: DEFAULT_THEMES }, workerManager, requestOwnerRender) {
136
140
  this.options = options;
137
141
  this.workerManager = workerManager;
138
- this.isContainerManaged = isContainerManaged;
142
+ this.requestOwnerRender = requestOwnerRender;
139
143
  this.hunksRenderer = this.createHunksRenderer(options);
140
144
  this.resizeManager = new ResizeManager();
141
145
  this.scrollSyncManager = new ScrollSyncManager();
@@ -254,27 +258,35 @@ var FileDiff = class {
254
258
  return resolveEditSessionSlotName(this.editSession?.annotations, annotation, getLineAnnotationName);
255
259
  };
256
260
  getLatestAnnotations() {
257
- return this.editSession?.annotations?.current ?? this.lineAnnotations;
261
+ return this.pendingData?.lineAnnotations ?? this.editSession?.annotations?.current ?? this.lineAnnotations;
262
+ }
263
+ getAnnotationsForDiff(fileDiff) {
264
+ const { pendingData } = this;
265
+ return pendingData != null && areDiffTargetsEqual(fileDiff, pendingData.fileDiff) ? pendingData.lineAnnotations : this.lineAnnotations;
258
266
  }
259
267
  isNewAnnotations(lineAnnotations) {
260
268
  const session = this.editSession?.annotations;
261
- if (lineAnnotations === this.lineAnnotations) return false;
269
+ if (lineAnnotations === this.getLatestAnnotations()) return false;
262
270
  return session == null || lineAnnotations !== session.provided && lineAnnotations !== session.current;
263
271
  }
264
272
  setLineAnnotations(lineAnnotations) {
265
273
  const sessionAnnotations = this.editSession?.annotations;
266
- if (sessionAnnotations == null) {
267
- this.lineAnnotations = lineAnnotations;
268
- return;
274
+ if (sessionAnnotations != null) {
275
+ if (!this.isNewAnnotations(lineAnnotations)) return;
276
+ writeEditSessionAnnotations(sessionAnnotations, lineAnnotations, getLineAnnotationName);
269
277
  }
270
- if (!this.isNewAnnotations(lineAnnotations)) return;
271
- this.lineAnnotations = lineAnnotations;
272
- writeEditSessionAnnotations(sessionAnnotations, lineAnnotations, getLineAnnotationName);
278
+ const fileDiff = this.getWorkingDiff();
279
+ if (fileDiff != null) this.pendingData = {
280
+ fileDiff,
281
+ lineAnnotations
282
+ };
273
283
  }
274
284
  syncEditSessionAnnotationsFromEditor(lineAnnotations) {
275
285
  const session = this.editSession?.annotations;
276
286
  if (session == null || lineAnnotations === session.current) return false;
277
287
  session.current = lineAnnotations;
288
+ if (this.renderedData != null) this.renderedData.lineAnnotations = lineAnnotations;
289
+ this.pendingData = void 0;
278
290
  this.hunksRenderer.setLineAnnotations(lineAnnotations);
279
291
  this.renderAnnotations();
280
292
  return true;
@@ -319,7 +331,7 @@ var FileDiff = class {
319
331
  }
320
332
  shouldApplyColumnVariables(overflow) {
321
333
  if (typeof this.options.hunkSeparators === "function") return true;
322
- return overflow === "scroll" && (this.getLatestAnnotations().length > 0 || this.pre?.hasAttribute("data-has-merge-conflict") === true);
334
+ return overflow === "scroll" && (this.lineAnnotations.length > 0 || this.pre?.hasAttribute("data-has-merge-conflict") === true);
323
335
  }
324
336
  getCodeScrollLeft() {
325
337
  return Math.max(this.codeUnified?.scrollLeft ?? 0, this.codeDeletions?.scrollLeft ?? 0, this.codeAdditions?.scrollLeft ?? 0);
@@ -348,10 +360,13 @@ var FileDiff = class {
348
360
  this.workerManager?.unsubscribeToThemeChanges(this);
349
361
  this.renderRange = void 0;
350
362
  if (!recycle) this.pendingFiles = void 0;
351
- if (!this.isContainerManaged) this.fileContainer?.remove();
363
+ if (!this.isComponentManaged) this.fileContainer?.remove();
352
364
  this.fileContainer = void 0;
353
365
  this.mounted = false;
354
- if (!recycle) this.lineAnnotations = [];
366
+ if (!recycle) {
367
+ this.renderedData = void 0;
368
+ this.pendingData = void 0;
369
+ }
355
370
  this.clearAuxiliaryNodes();
356
371
  this.annotationCache.clear();
357
372
  this.pre = void 0;
@@ -387,7 +402,6 @@ var FileDiff = class {
387
402
  this.workerManager = void 0;
388
403
  this.fileDiff = void 0;
389
404
  this.editSession = void 0;
390
- this.renderedDiff = void 0;
391
405
  this.deletionFile = void 0;
392
406
  this.additionFile = void 0;
393
407
  }
@@ -476,14 +490,19 @@ var FileDiff = class {
476
490
  this.hydrateMeasuredScrollbar();
477
491
  }
478
492
  hydrationSetup({ fileDiff, oldFile, newFile, lineAnnotations }) {
479
- this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;
493
+ const hydratedAnnotations = lineAnnotations ?? this.getLatestAnnotations();
494
+ this.pendingData = void 0;
480
495
  this.additionFile = newFile;
481
496
  this.deletionFile = oldFile;
482
497
  this.fileDiff = fileDiff ?? (oldFile !== void 0 && newFile !== void 0 ? parseDiffFromFile(oldFile, newFile, this.options.parseDiffOptions) : void 0);
498
+ this.renderedData = this.fileDiff != null ? {
499
+ fileDiff: this.fileDiff,
500
+ lineAnnotations: hydratedAnnotations
501
+ } : void 0;
502
+ if (this.fileDiff != null) this.adoptRenderData(this.fileDiff);
483
503
  if (this.pre == null) return;
484
504
  this.syncInteractionOptions();
485
505
  this.hunksRenderer.hydrate(this.fileDiff);
486
- this.renderedDiff = this.fileDiff;
487
506
  this.renderAnnotations();
488
507
  this.renderGutterUtility();
489
508
  this.injectUnsafeCSS();
@@ -491,12 +510,23 @@ var FileDiff = class {
491
510
  this.flushManagers();
492
511
  }
493
512
  rerender() {
494
- if (!this.enabled || this.fileDiff == null && this.additionFile == null && this.deletionFile == null) return;
513
+ if (!this.enabled || this.getInputDiff() == null && this.additionFile == null && this.deletionFile == null) return;
514
+ if (this.requestRender()) return;
495
515
  this.render({
496
516
  forceRender: true,
497
517
  renderRange: this.renderRange
498
518
  });
499
519
  }
520
+ requestRender() {
521
+ const { requestOwnerRender } = this;
522
+ if (this.editSession != null || requestOwnerRender == null) return false;
523
+ this.forceRenderOverride = true;
524
+ requestOwnerRender();
525
+ return true;
526
+ }
527
+ get isComponentManaged() {
528
+ return this.requestOwnerRender != null;
529
+ }
500
530
  onThemeChange() {
501
531
  this.hunksRenderer.clearRenderCache();
502
532
  this.rerender();
@@ -510,7 +540,8 @@ var FileDiff = class {
510
540
  this.rerender();
511
541
  };
512
542
  loadFilesIfNecessary() {
513
- const { fileDiff, options: { loadDiffFiles } } = this;
543
+ const fileDiff = this.getInputDiff();
544
+ const { loadDiffFiles } = this.options;
514
545
  if (fileDiff == null || !canHydrateDiff(fileDiff) || this.pendingFiles?.fileDiff === fileDiff) return;
515
546
  if (loadDiffFiles == null) throw new Error("FileDiff: loadDiffFiles is required to load full files for a partial diff");
516
547
  const promise = this.loadFilesForDiff(fileDiff, loadDiffFiles);
@@ -530,7 +561,8 @@ var FileDiff = class {
530
561
  * `loadDiffFiles` was passed in to `options`
531
562
  */
532
563
  __canAttachEditor() {
533
- return this.fileDiff != null && !this.fileDiff.isPartial;
564
+ const fileDiff = this.getInputDiff();
565
+ return fileDiff != null && !fileDiff.isPartial;
534
566
  }
535
567
  /**
536
568
  * Load a partial diff before starting a new edit session. Call this before
@@ -541,7 +573,8 @@ var FileDiff = class {
541
573
  if (this.__canAttachEditor()) return;
542
574
  const pending = this.__prepareForEditing();
543
575
  if (pending == null) {
544
- if (this.fileDiff?.isPartial === true && !canHydrateDiff(this.fileDiff)) throw new Error("FileDiff.prepareForEditing: this partial diff cannot be hydrated; provide a complete diff");
576
+ const fileDiff = this.getInputDiff();
577
+ if (fileDiff?.isPartial === true && !canHydrateDiff(fileDiff)) throw new Error("FileDiff.prepareForEditing: this partial diff cannot be hydrated; provide a complete diff");
545
578
  throw new Error("FileDiff.prepareForEditing: a partial diff requires loadDiffFiles");
546
579
  }
547
580
  await pending;
@@ -550,14 +583,15 @@ var FileDiff = class {
550
583
  /** Hydrate a diff if necessary */
551
584
  __prepareForEditing() {
552
585
  if (this.__canAttachEditor()) return;
553
- if (this.fileDiff?.isPartial === true && !canHydrateDiff(this.fileDiff)) throw new Error("FileDiff: this partial diff cannot be hydrated; provide a complete diff to edit");
586
+ const fileDiff = this.getInputDiff();
587
+ if (fileDiff?.isPartial === true && !canHydrateDiff(fileDiff)) throw new Error("FileDiff: this partial diff cannot be hydrated; provide a complete diff to edit");
554
588
  this.loadFilesIfNecessary();
555
589
  return this.pendingFiles?.promise;
556
590
  }
557
591
  async loadFilesForDiff(fileDiff, loadDiffFiles) {
558
592
  try {
559
593
  const files = await loadDiffFiles(fileDiff);
560
- if (this.fileDiff !== fileDiff) return;
594
+ if (this.getInputDiff() !== fileDiff) return;
561
595
  await this.handleFilesLoaded(fileDiff, files);
562
596
  } catch (error) {
563
597
  if (this.options.disableErrorHandling === true) throw error;
@@ -565,7 +599,7 @@ var FileDiff = class {
565
599
  }
566
600
  }
567
601
  async handleFilesLoaded(expectedDiff, files) {
568
- if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) return;
602
+ if (this.getInputDiff() !== expectedDiff || !expectedDiff.isPartial) return;
569
603
  hydratePartialDiff("merge", expectedDiff, files);
570
604
  this.setHydratedState(files);
571
605
  if (this.installHydratedSessionDiff(expectedDiff)) {
@@ -573,58 +607,69 @@ var FileDiff = class {
573
607
  return;
574
608
  }
575
609
  await awaitWithTimeout(() => this.primeHighlightCache(expectedDiff));
576
- if (!this.enabled || this.fileDiff !== expectedDiff) return;
610
+ if (!this.enabled || this.getInputDiff() !== expectedDiff) return;
577
611
  this.rerender();
578
612
  }
579
613
  installHydratedSessionDiff(expectedDiff) {
580
614
  if (expectedDiff.isPartial) throw new Error("FileDiff.installHydratedSessionDiff: diffs cannot be partial for editing");
581
- if (this.fileDiff !== expectedDiff) return false;
615
+ if (this.getInputDiff() !== expectedDiff) return false;
582
616
  if (this.editSession?.outgoingDiff != null) {
583
617
  this.installEditSession(expectedDiff);
584
618
  return true;
585
619
  }
586
620
  return false;
587
621
  }
588
- updateExternalDiff(incomingExternalDiff, lineAnnotations) {
589
- if (areDiffTargetsEqual(this.fileDiff, incomingExternalDiff)) return false;
590
- const outgoingDiff = this.editSession?.outgoingDiff ?? this.editSession?.diff;
591
- this.fileDiff = incomingExternalDiff;
592
- if (outgoingDiff != null) {
593
- if (incomingExternalDiff.isPartial) this.loadFilesIfNecessary();
594
- else this.installEditSession(incomingExternalDiff);
622
+ updateInputDiff(incomingDiff, lineAnnotations) {
623
+ if (areDiffTargetsEqual(this.getInputDiff(), incomingDiff)) return false;
624
+ const previousAnnotations = this.getLatestAnnotations();
625
+ this.fileDiff = incomingDiff;
626
+ const { editSession: previousSession } = this;
627
+ const outgoingDiff = previousSession?.outgoingDiff ?? previousSession?.diff;
628
+ if (previousSession != null) {
629
+ if (incomingDiff.isPartial) previousSession.inputDiff = incomingDiff;
630
+ else this.installEditSession(incomingDiff);
595
631
  if (this.editSession != null) this.editSession.outgoingDiff = outgoingDiff;
596
632
  }
597
- if (this.editSession?.annotations != null && lineAnnotations != null) {
598
- this.lineAnnotations = lineAnnotations;
599
- this.editSession.annotations = adoptEditSessionAnnotations(lineAnnotations, getLineAnnotationName, this.editSession.annotations);
600
- }
633
+ if (this.editSession?.annotations != null && lineAnnotations != null) this.editSession.annotations = adoptEditSessionAnnotations(lineAnnotations, getLineAnnotationName, this.editSession.annotations);
634
+ this.pendingData = {
635
+ fileDiff: this.editSession?.diff ?? incomingDiff,
636
+ lineAnnotations: this.editSession?.annotations?.current ?? lineAnnotations ?? previousAnnotations
637
+ };
638
+ if (outgoingDiff != null && incomingDiff.isPartial) this.loadFilesIfNecessary();
601
639
  return true;
602
640
  }
603
- installEditSession(externalDiff, retainedDocument, retainedSession) {
604
- const externalContents = externalDiff.additionLines.join("");
641
+ installEditSession(inputDiff, retainedDocument, retainedSession) {
642
+ const inputContents = inputDiff.additionLines.join("");
605
643
  const retainedLines = retainedDocument != null ? splitFileContents(retainedDocument.contents) : void 0;
606
- const restoreRetainedSession = retainedSession != null && canRestoreDiffSession(retainedSession, externalDiff);
644
+ const restoreRetainedSession = retainedSession != null && canRestoreDiffSession(retainedSession, inputDiff);
607
645
  if (retainedSession != null && !restoreRetainedSession) throw new Error("FileDiff: retained session cannot resume against a different old file");
608
- if (retainedDocument != null && retainedDocument.contents !== externalContents && !restoreRetainedSession) throw new Error("FileDiff: retained edits are missing their diff session state");
609
- const usesExternalDocument = retainedDocument == null || retainedDocument.name === externalDiff.name && retainedDocument.lang === externalDiff.lang && retainedDocument.contents === externalContents;
610
- const sessionDiff = createEditSessionDiff(externalDiff);
611
- if (retainedDocument != null && retainedLines != null && !usesExternalDocument) {
646
+ if (retainedDocument != null && retainedDocument.contents !== inputContents && !restoreRetainedSession) throw new Error("FileDiff: retained edits are missing their diff session state");
647
+ const usesInputDocument = retainedDocument == null || retainedDocument.name === inputDiff.name && retainedDocument.lang === inputDiff.lang && retainedDocument.contents === inputContents;
648
+ const sessionDiff = createEditSessionDiff(inputDiff);
649
+ if (retainedDocument != null && retainedLines != null && !usesInputDocument) {
612
650
  sessionDiff.name = retainedDocument.name;
613
651
  sessionDiff.lang = retainedDocument.lang;
614
652
  }
615
- if (restoreRetainedSession && retainedSession != null && retainedLines != null) {
653
+ if (restoreRetainedSession && retainedSession != null && retainedDocument != null && retainedLines != null) {
616
654
  sessionDiff.additionLines = retainedLines;
655
+ sessionDiff.additionCharacterCount = retainedDocument.contents.length;
617
656
  sessionDiff.type = retainedSession.type;
618
657
  sessionDiff.hunks = retainedSession.hunks;
619
658
  sessionDiff.editSessionDirty = true;
620
659
  recomputeDiffRenderLineCounts(sessionDiff);
621
660
  }
661
+ const annotations = this.editSession?.annotations ?? adoptEditSessionAnnotations(this.getLatestAnnotations(), getLineAnnotationName);
622
662
  this.editSession = {
623
663
  diff: sessionDiff,
624
- annotations: this.editSession?.annotations ?? adoptEditSessionAnnotations(this.lineAnnotations, getLineAnnotationName),
664
+ inputDiff,
665
+ annotations,
625
666
  outgoingDiff: this.editSession?.outgoingDiff
626
667
  };
627
- this.hunksRenderer.beginEditSession(sessionDiff, usesExternalDocument && !restoreRetainedSession ? externalDiff : void 0);
668
+ this.pendingData = {
669
+ fileDiff: sessionDiff,
670
+ lineAnnotations: annotations.current
671
+ };
672
+ this.hunksRenderer.beginEditSession(sessionDiff, usesInputDocument && !restoreRetainedSession ? inputDiff : void 0);
628
673
  }
629
674
  setHydratedState(files) {
630
675
  this.deletionFile = files.oldFile;
@@ -634,6 +679,8 @@ var FileDiff = class {
634
679
  }
635
680
  render({ fileDiff, deferManagers = false, forceRender = false, preventEmit = false, lineAnnotations, fileContainer, containerWrapper, renderRange, ...fileInputProps }) {
636
681
  if (!this.enabled) throw new Error("FileDiff.render: attempting to call render after cleaned up");
682
+ forceRender = this.forceRenderOverride ?? forceRender;
683
+ this.forceRenderOverride = void 0;
637
684
  const fileInput = getDiffFileInput(fileInputProps, "FileDiff.render");
638
685
  const oldFile = fileInput?.oldFile;
639
686
  const newFile = fileInput?.newFile;
@@ -643,7 +690,7 @@ var FileDiff = class {
643
690
  const themeChanged = this.hasThemeChanged();
644
691
  const hasFileInput = fileInput != null;
645
692
  const filesDidChange = hasFileInput && (!areOptionalFilesEqual(oldFile, this.deletionFile) || !areOptionalFilesEqual(newFile, this.additionFile));
646
- let diffDidChange = fileDiff != null && !areDiffTargetsEqual(fileDiff, this.fileDiff);
693
+ let diffDidChange = fileDiff != null && !areDiffTargetsEqual(fileDiff, this.getInputDiff());
647
694
  const annotationsChanged = lineAnnotations != null && (lineAnnotations.length > 0 || this.getLatestAnnotations().length > 0) ? this.isNewAnnotations(lineAnnotations) : false;
648
695
  if (!collapsed && areRenderRangesEqual(nextRenderRange, this.renderRange) && !forceRender && !annotationsChanged && !themeChanged && (fileDiff != null && !diffDidChange || fileDiff == null && !filesDidChange)) {
649
696
  const rendered = this.applyCachedThemeState(themeType);
@@ -651,7 +698,7 @@ var FileDiff = class {
651
698
  return rendered;
652
699
  }
653
700
  let nextParsedFileDiff;
654
- if (fileDiff == null && hasFileInput && (filesDidChange || this.fileDiff == null)) nextParsedFileDiff = parseDiffFromFile(fileInput.oldFile, fileInput.newFile, this.options.parseDiffOptions);
701
+ if (fileDiff == null && hasFileInput && (filesDidChange || this.getInputDiff() == null)) nextParsedFileDiff = parseDiffFromFile(fileInput.oldFile, fileInput.newFile, this.options.parseDiffOptions);
655
702
  const { renderRange: previousRenderRange } = this;
656
703
  this.renderRange = nextRenderRange;
657
704
  if (hasFileInput) {
@@ -661,23 +708,23 @@ var FileDiff = class {
661
708
  this.deletionFile = void 0;
662
709
  this.additionFile = void 0;
663
710
  }
664
- if (fileDiff != null && diffDidChange) this.updateExternalDiff(fileDiff, lineAnnotations);
711
+ if (fileDiff != null && diffDidChange) this.updateInputDiff(fileDiff, lineAnnotations);
665
712
  else if (nextParsedFileDiff != null) {
666
713
  diffDidChange = true;
667
- this.updateExternalDiff(nextParsedFileDiff, lineAnnotations);
714
+ this.updateInputDiff(nextParsedFileDiff, lineAnnotations);
668
715
  }
669
716
  if (diffDidChange) this.clearReusableHeader();
670
717
  if (lineAnnotations != null) this.setLineAnnotations(lineAnnotations);
671
- const latestDiff = this.getLatestDiff();
672
- if (latestDiff == null) return false;
673
- if (latestDiff.editSessionDirty === true && this.shouldSelfHealEditSession()) {
674
- finishEditSessionForDiff(latestDiff, this.options.parseDiffOptions);
718
+ const workingDiff = this.getWorkingDiff();
719
+ if (workingDiff == null) return false;
720
+ if (workingDiff.editSessionDirty === true && this.shouldSelfHealEditSession()) {
721
+ finishEditSessionForDiff(workingDiff, this.options.parseDiffOptions);
675
722
  this.hunksRenderer.refreshHighlightedResult();
676
723
  }
677
724
  if (expandUnchanged) this.loadFilesIfNecessary();
678
725
  this.hunksRenderer.setOptions(this.getHunksRendererOptions(this.options));
679
726
  this.syncInteractionOptions();
680
- this.hunksRenderer.setLineAnnotations(this.getLatestAnnotations());
727
+ this.prepareRenderData(this.hunksRenderer.getDiffForNextRender(workingDiff));
681
728
  const { disableErrorHandling = false, disableFileHeader = false } = this.options;
682
729
  if (disableFileHeader) {
683
730
  if (this.headerElement != null) {
@@ -693,11 +740,11 @@ var FileDiff = class {
693
740
  this.removeRenderedCode();
694
741
  this.clearAuxiliaryNodes();
695
742
  try {
696
- const hunksResult = this.hunksRenderer.renderDiff(latestDiff, EMPTY_RENDER_RANGE);
743
+ const hunksResult = this.hunksRenderer.renderDiff(workingDiff, EMPTY_RENDER_RANGE);
697
744
  if (hunksResult != null) this.applyThemeState(fileContainer, hunksResult.themeStyles, themeType, hunksResult.baseThemeType);
698
745
  if (hunksResult?.headerElement != null) this.applyHeaderToDOM(hunksResult.headerElement, fileContainer, hunksResult.fileDiff);
699
746
  this.renderSeparators([]);
700
- this.renderedDiff = hunksResult?.fileDiff ?? latestDiff;
747
+ this.adoptRenderData(hunksResult?.fileDiff ?? workingDiff);
701
748
  this.injectUnsafeCSS();
702
749
  } catch (error) {
703
750
  if (disableErrorHandling) throw error;
@@ -710,12 +757,12 @@ var FileDiff = class {
710
757
  }
711
758
  try {
712
759
  const pre = this.getOrCreatePreNode(fileContainer);
713
- if (!(this.canPartiallyRender(forceRender, annotationsChanged, filesDidChange || diffDidChange || themeChanged || !areDiffTargetsEqual(this.renderedDiff, latestDiff)) && this.applyPartialRender({
714
- fileDiff: latestDiff,
760
+ if (!(this.canPartiallyRender(forceRender, annotationsChanged, filesDidChange || diffDidChange || themeChanged || !areDiffTargetsEqual(this.getRenderedDiff(), workingDiff)) && this.applyPartialRender({
761
+ fileDiff: workingDiff,
715
762
  previousRenderRange,
716
763
  renderRange: nextRenderRange
717
764
  }))) {
718
- const hunksResult = this.hunksRenderer.renderDiff(latestDiff, nextRenderRange);
765
+ const hunksResult = this.hunksRenderer.renderDiff(workingDiff, nextRenderRange);
719
766
  if (hunksResult == null) {
720
767
  if (this.workerManager?.isInitialized() === false && this.workerManager.isWorkingPool()) this.workerManager.initialize().catch(() => {}).then(() => this.rerender());
721
768
  return false;
@@ -728,7 +775,10 @@ var FileDiff = class {
728
775
  this.pre = void 0;
729
776
  }
730
777
  this.renderSeparators(hunksResult.hunkData);
731
- this.renderedDiff = hunksResult.fileDiff;
778
+ this.adoptRenderData(hunksResult.fileDiff);
779
+ } else {
780
+ const renderedDiff = this.getRenderedDiff();
781
+ if (renderedDiff != null) this.adoptRenderData(renderedDiff);
732
782
  }
733
783
  this.applyBuffers(pre, nextRenderRange);
734
784
  this.injectUnsafeCSS();
@@ -761,24 +811,56 @@ var FileDiff = class {
761
811
  this.mounted = true;
762
812
  onPostRender?.(fileContainer, this, phase);
763
813
  }
764
- getLatestDiff(fileDiff = this.fileDiff) {
765
- return this.editSession?.diff ?? fileDiff;
814
+ getInputDiff() {
815
+ return this.fileDiff;
816
+ }
817
+ getWorkingDiff(fallbackDiff = this.fileDiff) {
818
+ return this.editSession?.diff ?? fallbackDiff;
766
819
  }
767
820
  getRenderedDiff() {
768
- return this.renderedDiff;
821
+ return this.renderedData?.fileDiff;
822
+ }
823
+ /**
824
+ * @internal Data the next render() with this input will display. While a
825
+ * replacement diff is being highlighted, this is still the displayed data.
826
+ */
827
+ __getNextRenderData({ fileDiff, lineAnnotations }) {
828
+ const sessionAnnotations = this.editSession?.annotations;
829
+ if (sessionAnnotations != null) return {
830
+ fileDiff,
831
+ lineAnnotations: lineAnnotations != null && this.isNewAnnotations(lineAnnotations) ? lineAnnotations : sessionAnnotations.provided
832
+ };
833
+ const workingDiff = this.getWorkingDiff(fileDiff) ?? fileDiff;
834
+ const nextDiff = this.hunksRenderer.getDiffForNextRender(workingDiff);
835
+ return {
836
+ fileDiff: nextDiff,
837
+ lineAnnotations: lineAnnotations != null && areDiffTargetsEqual(nextDiff, workingDiff) ? lineAnnotations : this.getAnnotationsForDiff(nextDiff)
838
+ };
839
+ }
840
+ prepareRenderData(fileDiff) {
841
+ this.hunksRenderer.setLineAnnotations(this.getAnnotationsForDiff(fileDiff));
842
+ }
843
+ adoptRenderData(fileDiff) {
844
+ const { pendingData } = this;
845
+ const matchesPending = pendingData != null && areDiffTargetsEqual(fileDiff, pendingData.fileDiff);
846
+ this.renderedData = {
847
+ fileDiff,
848
+ lineAnnotations: matchesPending ? pendingData.lineAnnotations : this.lineAnnotations
849
+ };
850
+ if (matchesPending) this.pendingData = void 0;
769
851
  }
770
852
  syncRenderViewToEditor() {
771
853
  const { editor, fileContainer } = this;
772
854
  const lineAnnotations = this.getLatestAnnotations();
773
855
  const renderRange = this.computeEditorRenderRange(this.renderRange);
774
- const fileDiff = this.getLatestDiff();
856
+ const fileDiff = this.getWorkingDiff();
775
857
  if (editor == null || fileContainer == null || fileDiff == null || fileDiff.isPartial) return;
776
858
  const sync = (highlighter) => {
777
- if (!this.enabled || this.editor !== editor || this.fileContainer !== fileContainer || this.getLatestDiff() !== fileDiff) return;
859
+ if (!this.enabled || this.editor !== editor || this.fileContainer !== fileContainer || this.getWorkingDiff() !== fileDiff) return;
778
860
  const replacement = this.editSession?.outgoingDiff;
779
- const { fileDiff: externalDiff } = this;
780
- const externalDocument = replacement != null && externalDiff != null && replacement !== fileDiff;
781
- const resetHistory = externalDocument && replacement != null && externalDiff != null ? shouldResetUndoState(replacement, externalDiff) : false;
861
+ const inputDiff = this.getInputDiff();
862
+ const externalDocument = replacement != null && inputDiff != null && replacement !== fileDiff;
863
+ const resetHistory = externalDocument && replacement != null && inputDiff != null ? shouldResetUndoState(replacement, inputDiff) : false;
782
864
  editor.__syncRenderView({
783
865
  highlighter,
784
866
  fileContainer,
@@ -805,7 +887,7 @@ var FileDiff = class {
805
887
  });
806
888
  }
807
889
  computeEditorRenderRange(renderRange) {
808
- const fileDiff = this.getLatestDiff();
890
+ const fileDiff = this.getWorkingDiff();
809
891
  if (renderRange == null || fileDiff == null || isDefaultRenderRange(renderRange)) return renderRange;
810
892
  const { diffStyle = "split", expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
811
893
  let firstLineNumber;
@@ -855,7 +937,8 @@ var FileDiff = class {
855
937
  * When `clone` is true, the returned lines and hunks are copied.
856
938
  */
857
939
  __captureDocumentSessionState(clone = true) {
858
- let { fileDiff, editSession: { diff: sessionDiff, outgoingDiff } = {} } = this;
940
+ const fileDiff = this.getInputDiff();
941
+ let { diff: sessionDiff, outgoingDiff } = this.editSession ?? {};
859
942
  if (outgoingDiff != null && fileDiff != null) {
860
943
  if (!fileDiff.isPartial && shouldResetUndoState(outgoingDiff, fileDiff)) return;
861
944
  sessionDiff = outgoingDiff;
@@ -896,17 +979,17 @@ var FileDiff = class {
896
979
  this.resumeEditorRendering(editor);
897
980
  }
898
981
  resumeEditorRendering(editor) {
899
- const { fileDiff: externalDiff } = this;
982
+ const inputDiff = this.getInputDiff();
900
983
  const pendingReplacement = this.editSession?.outgoingDiff;
901
- if (pendingReplacement != null && externalDiff != null && !externalDiff.isPartial && this.editSession?.diff === pendingReplacement) this.installEditSession(externalDiff);
902
- const initialExternalDiff = this.editSession == null && externalDiff != null && !externalDiff.isPartial ? externalDiff : void 0;
903
- if (initialExternalDiff != null) this.installEditSession(initialExternalDiff, editor.__getDocumentContents(getAdditionFile(initialExternalDiff)), editor.__getDocumentSessionState());
984
+ if (pendingReplacement != null && inputDiff != null && !inputDiff.isPartial && this.editSession?.diff === pendingReplacement) this.installEditSession(inputDiff);
985
+ const initialInputDiff = this.editSession == null && inputDiff != null && !inputDiff.isPartial ? inputDiff : void 0;
986
+ if (initialInputDiff != null) this.installEditSession(initialInputDiff, editor.__getDocumentContents(getAdditionFile(initialInputDiff)), editor.__getDocumentSessionState());
904
987
  else if (this.editSession != null) this.hunksRenderer.beginEditSession(this.editSession.diff);
905
988
  this.editor = editor;
906
- if (this.fileDiff?.isPartial === true) this.loadFilesIfNecessary();
989
+ if (this.getInputDiff()?.isPartial === true) this.loadFilesIfNecessary();
907
990
  const editSessionDiff = this.editSession?.diff;
908
991
  if (this.hunksRenderer.editorRenderReady()) {
909
- if (editSessionDiff != null && this.hunksRenderer.diffCache === editSessionDiff) this.renderedDiff = editSessionDiff;
992
+ if (editSessionDiff != null && this.hunksRenderer.diffCache === editSessionDiff) this.adoptRenderData(editSessionDiff);
910
993
  this.syncRenderViewToEditor();
911
994
  } else this.rerender();
912
995
  }
@@ -921,7 +1004,7 @@ var FileDiff = class {
921
1004
  * Requires the editor to be detached first. Does nothing when no session
922
1005
  * exists, so callers can invoke it again safely after it has settled.
923
1006
  *
924
- * `onEditComplete` receives the completed diff, current external diff,
1007
+ * `onEditComplete` receives the completed diff, current input diff,
925
1008
  * complete file pair, and both annotation collections even when the final
926
1009
  * text is unchanged. In `install` mode, accepting installs the completed diff
927
1010
  * and its annotations; rejecting or having no handler restores the external
@@ -932,9 +1015,10 @@ var FileDiff = class {
932
1015
  this.settleEditSession(mode === "install", editor);
933
1016
  }
934
1017
  settleEditSession(installResult, editor) {
935
- const { editSession, fileDiff: externalDiff, lineAnnotations: externalAnnotations } = this;
936
- if (editSession == null || externalDiff == null) return;
937
- const { diff: editSessionDiff, annotations: editSessionAnnotations } = editSession;
1018
+ const { editSession } = this;
1019
+ if (editSession == null) return;
1020
+ const { diff: editSessionDiff, inputDiff, annotations: editSessionAnnotations } = editSession;
1021
+ const inputAnnotations = editSessionAnnotations?.provided ?? this.lineAnnotations;
938
1022
  if (this.editor != null) throw new Error("FileDiff.__completeEditSession: detach the editor before completing the session");
939
1023
  this.hunksRenderer.endEditSession();
940
1024
  this.finalizeEditSessionHunks();
@@ -954,20 +1038,20 @@ var FileDiff = class {
954
1038
  const event = {
955
1039
  fileDiff: completedDiff,
956
1040
  editor,
957
- originalFileDiff: externalDiff,
1041
+ originalFileDiff: inputDiff,
958
1042
  oldFile: completedDiff.type === "new" ? null : {
959
1043
  name: completedDiff.prevName ?? completedDiff.name,
960
1044
  contents: completedDiff.deletionLines.join("")
961
1045
  },
962
1046
  newFile,
963
1047
  lineAnnotations: sessionAnnotationsCurrent,
964
- originalLineAnnotations: externalAnnotations
1048
+ originalLineAnnotations: inputAnnotations
965
1049
  };
966
1050
  Object.freeze(event);
967
1051
  try {
968
1052
  editor.__emitEditComplete(event);
969
1053
  if (this.options.onEditComplete?.(event) === "accept") {
970
- if (completedDiff.cacheKey != null && completedDiff.cacheKey === externalDiff.cacheKey) throw new Error("FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey");
1054
+ if (completedDiff.cacheKey != null && completedDiff.cacheKey === inputDiff.cacheKey) throw new Error("FileDiff.__completeEditSession: an accepted diff must not reuse the replaced diff cacheKey");
971
1055
  acceptedDiff = completedDiff;
972
1056
  acceptedOldFile = event.oldFile;
973
1057
  acceptedNewFile = event.newFile;
@@ -977,14 +1061,17 @@ var FileDiff = class {
977
1061
  failure = error;
978
1062
  }
979
1063
  if (installResult && acceptedDiff != null) {
980
- this.fileDiff = acceptedDiff;
981
1064
  if (this.additionFile != null) {
982
1065
  this.deletionFile = acceptedOldFile;
983
1066
  this.additionFile = acceptedNewFile;
984
1067
  }
985
- if (sessionAnnotationsCurrent != null) this.lineAnnotations = sessionAnnotationsCurrent;
986
1068
  }
987
1069
  this.editSession = void 0;
1070
+ this.fileDiff = installResult && acceptedDiff != null ? acceptedDiff : inputDiff;
1071
+ this.pendingData = {
1072
+ fileDiff: this.fileDiff,
1073
+ lineAnnotations: installResult && acceptedDiff != null ? sessionAnnotationsCurrent ?? inputAnnotations : inputAnnotations
1074
+ };
988
1075
  if (installResult && this.fileContainer != null) this.rerender();
989
1076
  if (failed) throw failure;
990
1077
  }
@@ -1001,7 +1088,7 @@ var FileDiff = class {
1001
1088
  * ran.
1002
1089
  */
1003
1090
  finalizeEditSessionHunks() {
1004
- const fileDiff = this.getLatestDiff();
1091
+ const fileDiff = this.getWorkingDiff();
1005
1092
  if (fileDiff == null || fileDiff.editSessionDirty !== true) return false;
1006
1093
  const { collapsedContextThreshold = 1 } = this.options;
1007
1094
  const anchors = captureExpansionAnchors(fileDiff, this.hunksRenderer.getExpandedHunksMap(), collapsedContextThreshold);
@@ -1053,9 +1140,8 @@ var FileDiff = class {
1053
1140
  }
1054
1141
  }
1055
1142
  detachAdditionLines() {
1056
- const editSessionDiff = this.editSession?.diff;
1057
- const { fileDiff } = this;
1058
- if (editSessionDiff != null && (editSessionDiff.additionLines === fileDiff?.additionLines || editSessionDiff.additionLines === editSessionDiff.deletionLines)) editSessionDiff.additionLines = [...editSessionDiff.additionLines];
1143
+ const { diff: editSessionDiff, inputDiff } = this.editSession ?? {};
1144
+ if (editSessionDiff != null && (editSessionDiff.additionLines === inputDiff?.additionLines || editSessionDiff.additionLines === editSessionDiff.deletionLines)) editSessionDiff.additionLines = [...editSessionDiff.additionLines];
1059
1145
  }
1060
1146
  isLineRenderable(lineNumber) {
1061
1147
  const fileDiff = this.getRenderedDiff();
@@ -1173,7 +1259,7 @@ var FileDiff = class {
1173
1259
  this.placeHolder.style.setProperty("height", `${height}px`);
1174
1260
  return true;
1175
1261
  }
1176
- async primeHighlightCache(fileDiff = this.fileDiff) {
1262
+ async primeHighlightCache(fileDiff = this.getInputDiff()) {
1177
1263
  const { workerManager } = this;
1178
1264
  if (fileDiff == null || workerManager == null || !workerManager.isWorkingPool() || fileDiff.cacheKey == null || isDiffPlainText(fileDiff)) return;
1179
1265
  const tokenizeMaxLength = this.options.tokenizeMaxLength ?? 1e5;
@@ -1227,7 +1313,7 @@ var FileDiff = class {
1227
1313
  }
1228
1314
  renderSeparators(hunkData) {
1229
1315
  const { hunkSeparators } = this.options;
1230
- if (this.isContainerManaged || this.fileContainer == null || typeof hunkSeparators !== "function") {
1316
+ if (this.isComponentManaged || this.fileContainer == null || typeof hunkSeparators !== "function") {
1231
1317
  for (const { element } of this.separatorCache.values()) element.remove();
1232
1318
  this.separatorCache.clear();
1233
1319
  return;
@@ -1258,31 +1344,34 @@ var FileDiff = class {
1258
1344
  }
1259
1345
  }
1260
1346
  renderAnnotations() {
1261
- if (this.isContainerManaged || this.fileContainer == null) {
1347
+ if (this.isComponentManaged || this.fileContainer == null) {
1262
1348
  for (const { element } of this.annotationCache.values()) element.remove();
1263
1349
  this.annotationCache.clear();
1264
1350
  return;
1265
1351
  }
1266
1352
  const staleAnnotations = new Map(this.annotationCache);
1267
- const { renderAnnotation } = this.options;
1268
- const lineAnnotations = this.getLatestAnnotations();
1269
- if (renderAnnotation != null && lineAnnotations.length > 0) for (const [index, annotation] of lineAnnotations.entries()) {
1270
- const name = this.getAnnotationSlotName(annotation);
1271
- const id = `${index}-${name}`;
1272
- let cache = this.annotationCache.get(id);
1273
- if (cache == null || !areDiffLineAnnotationsEqual(annotation, cache.annotation)) {
1274
- cache?.element.remove();
1275
- const content = renderAnnotation(annotation);
1276
- if (content == null) continue;
1277
- cache = {
1278
- element: createAnnotationWrapperNode(name),
1279
- annotation
1280
- };
1281
- cache.element.appendChild(content);
1282
- this.fileContainer.appendChild(cache.element);
1283
- this.annotationCache.set(id, cache);
1353
+ const { renderedData, options: { renderAnnotation } } = this;
1354
+ if (renderAnnotation != null && renderedData != null) {
1355
+ const { fileDiff, lineAnnotations } = renderedData;
1356
+ for (const [index, annotation] of lineAnnotations.entries()) {
1357
+ const name = this.getAnnotationSlotName(annotation);
1358
+ const id = `${index}-${name}`;
1359
+ let cache = this.annotationCache.get(id);
1360
+ if (cache == null || cache.fileDiff !== fileDiff || !areDiffLineAnnotationsEqual(annotation, cache.annotation)) {
1361
+ cache?.element.remove();
1362
+ const content = renderAnnotation(annotation, fileDiff);
1363
+ if (content == null) continue;
1364
+ cache = {
1365
+ element: createAnnotationWrapperNode(name),
1366
+ annotation,
1367
+ fileDiff
1368
+ };
1369
+ cache.element.appendChild(content);
1370
+ this.fileContainer.appendChild(cache.element);
1371
+ this.annotationCache.set(id, cache);
1372
+ }
1373
+ staleAnnotations.delete(id);
1284
1374
  }
1285
- staleAnnotations.delete(id);
1286
1375
  }
1287
1376
  for (const [id, { element }] of staleAnnotations.entries()) {
1288
1377
  this.annotationCache.delete(id);
@@ -1393,7 +1482,7 @@ var FileDiff = class {
1393
1482
  this.headerElement = newHeader;
1394
1483
  this.headerCache.lastRenderedHTML = headerHTML;
1395
1484
  }
1396
- if (this.isContainerManaged) return;
1485
+ if (this.isComponentManaged) return;
1397
1486
  const { renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata } = this.options;
1398
1487
  if (renderCustomHeader != null) {
1399
1488
  const content = renderCustomHeader(fileDiff) ?? void 0;
@@ -1644,7 +1733,7 @@ var FileDiff = class {
1644
1733
  else if (diffStyle === "split" && Array.isArray(codeElements)) this.insertPartialHTML(diffStyle, codeElements, result, insertPosition);
1645
1734
  else throw new Error("FileDiff.applyPartialRender.applyChunk: invalid chunk application");
1646
1735
  rowCount += result.rowCount;
1647
- this.renderedDiff = result.fileDiff;
1736
+ this.adoptRenderData(result.fileDiff);
1648
1737
  };
1649
1738
  this.cleanupErrorWrapper();
1650
1739
  applyChunk(prependResult, "afterbegin");
@@ -1667,7 +1756,7 @@ var FileDiff = class {
1667
1756
  } else throw new Error("FileDiff.insertPartialHTML: Invalid argument composition");
1668
1757
  }
1669
1758
  refreshSplitDiffView() {
1670
- const fileDiff = this.getLatestDiff();
1759
+ const fileDiff = this.getWorkingDiff();
1671
1760
  if (this.options.diffStyle !== "split" || fileDiff == null) return;
1672
1761
  const hunksResult = this.hunksRenderer.renderDiff(fileDiff, this.renderRange);
1673
1762
  if (hunksResult == null) return;
@@ -1686,10 +1775,10 @@ var FileDiff = class {
1686
1775
  };
1687
1776
  applyLineType("deletions", columns[0]);
1688
1777
  applyLineType("additions", columns[1]);
1689
- this.renderedDiff = hunksResult.fileDiff;
1778
+ this.adoptRenderData(hunksResult.fileDiff);
1690
1779
  }
1691
1780
  refreshUnifiedDiffView() {
1692
- const fileDiff = this.getLatestDiff();
1781
+ const fileDiff = this.getWorkingDiff();
1693
1782
  if (this.options.diffStyle !== "unified" || fileDiff == null) return;
1694
1783
  const hunksResult = this.hunksRenderer.renderDiff(fileDiff, this.renderRange);
1695
1784
  if (hunksResult == null) return;
@@ -1704,7 +1793,7 @@ var FileDiff = class {
1704
1793
  this.applyRowSpan("unified", columns, hunksResult.rowCount);
1705
1794
  this.lastRowCount = hunksResult.rowCount;
1706
1795
  }
1707
- this.renderedDiff = hunksResult.fileDiff;
1796
+ this.adoptRenderData(hunksResult.fileDiff);
1708
1797
  };
1709
1798
  if (this.shouldGuardRebuildScroll()) guardWebKitScrollDuringRebuild(this.pre, applyColumns);
1710
1799
  else applyColumns();