@pierre/diffs 1.3.0-beta.8 → 1.3.0-rc.1

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 (229) hide show
  1. package/dist/components/CodeView.d.ts +12 -12
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +51 -43
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +7 -2
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +36 -8
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +34 -6
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +198 -17
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/FileStream.d.ts.map +1 -1
  14. package/dist/components/FileStream.js +2 -1
  15. package/dist/components/FileStream.js.map +1 -1
  16. package/dist/components/VirtualizedFile.d.ts +2 -1
  17. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  18. package/dist/components/VirtualizedFile.js +9 -5
  19. package/dist/components/VirtualizedFile.js.map +1 -1
  20. package/dist/components/VirtualizedFileDiff.d.ts +14 -0
  21. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  22. package/dist/components/VirtualizedFileDiff.js +61 -3
  23. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  24. package/dist/components/Virtualizer.d.ts +14 -2
  25. package/dist/components/Virtualizer.d.ts.map +1 -1
  26. package/dist/components/Virtualizer.js +29 -3
  27. package/dist/components/Virtualizer.js.map +1 -1
  28. package/dist/edit/index.d.ts +5 -0
  29. package/dist/edit/index.js +3 -0
  30. package/dist/editor/command.d.ts +1 -1
  31. package/dist/editor/command.d.ts.map +1 -1
  32. package/dist/editor/command.js +11 -0
  33. package/dist/editor/command.js.map +1 -1
  34. package/dist/editor/editStack.d.ts +6 -2
  35. package/dist/editor/editStack.d.ts.map +1 -1
  36. package/dist/editor/editStack.js +54 -13
  37. package/dist/editor/editStack.js.map +1 -1
  38. package/dist/editor/editor.d.ts +51 -23
  39. package/dist/editor/editor.d.ts.map +1 -1
  40. package/dist/editor/editor.js +995 -242
  41. package/dist/editor/editor.js.map +1 -1
  42. package/dist/editor/editor2.js +1 -1
  43. package/dist/editor/languages.d.ts +26 -0
  44. package/dist/editor/languages.d.ts.map +1 -0
  45. package/dist/editor/languages.js +363 -0
  46. package/dist/editor/languages.js.map +1 -0
  47. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  48. package/dist/editor/lineAnnotations.js +25 -26
  49. package/dist/editor/lineAnnotations.js.map +1 -1
  50. package/dist/editor/marker.d.ts +5 -3
  51. package/dist/editor/marker.d.ts.map +1 -1
  52. package/dist/editor/marker.js +111 -91
  53. package/dist/editor/marker.js.map +1 -1
  54. package/dist/editor/matchBrackets.d.ts +3 -2
  55. package/dist/editor/matchBrackets.d.ts.map +1 -1
  56. package/dist/editor/matchBrackets.js +2 -10
  57. package/dist/editor/matchBrackets.js.map +1 -1
  58. package/dist/editor/pieceTable.d.ts +2 -1
  59. package/dist/editor/pieceTable.d.ts.map +1 -1
  60. package/dist/editor/pieceTable.js +103 -39
  61. package/dist/editor/pieceTable.js.map +1 -1
  62. package/dist/editor/platform.js +2 -0
  63. package/dist/editor/platform.js.map +1 -1
  64. package/dist/editor/popover.d.ts +25 -5
  65. package/dist/editor/popover.d.ts.map +1 -1
  66. package/dist/editor/popover.js +60 -14
  67. package/dist/editor/popover.js.map +1 -1
  68. package/dist/editor/searchPanel.d.ts +1 -0
  69. package/dist/editor/searchPanel.d.ts.map +1 -1
  70. package/dist/editor/searchPanel.js +15 -8
  71. package/dist/editor/searchPanel.js.map +1 -1
  72. package/dist/editor/selection.d.ts +31 -11
  73. package/dist/editor/selection.d.ts.map +1 -1
  74. package/dist/editor/selection.js +198 -70
  75. package/dist/editor/selection.js.map +1 -1
  76. package/dist/editor/selectionAction.d.ts +4 -3
  77. package/dist/editor/selectionAction.d.ts.map +1 -1
  78. package/dist/editor/selectionAction.js +9 -5
  79. package/dist/editor/selectionAction.js.map +1 -1
  80. package/dist/editor/stateStorage.d.ts +15 -0
  81. package/dist/editor/stateStorage.d.ts.map +1 -0
  82. package/dist/editor/stateStorage.js +65 -0
  83. package/dist/editor/stateStorage.js.map +1 -0
  84. package/dist/editor/textDocument.d.ts +12 -77
  85. package/dist/editor/textDocument.d.ts.map +1 -1
  86. package/dist/editor/textDocument.js +76 -34
  87. package/dist/editor/textDocument.js.map +1 -1
  88. package/dist/editor/textMeasure.d.ts +7 -12
  89. package/dist/editor/textMeasure.d.ts.map +1 -1
  90. package/dist/editor/textMeasure.js +40 -32
  91. package/dist/editor/textMeasure.js.map +1 -1
  92. package/dist/editor/{tokenzier.d.ts → tokenizer.d.ts} +3 -3
  93. package/dist/editor/tokenizer.d.ts.map +1 -0
  94. package/dist/editor/{tokenzier.js → tokenizer.js} +91 -26
  95. package/dist/editor/tokenizer.js.map +1 -0
  96. package/dist/editor/utils.js +1 -1
  97. package/dist/editor/utils.js.map +1 -1
  98. package/dist/index.d.ts +5 -4
  99. package/dist/index.js +7 -6
  100. package/dist/managers/InteractionManager.d.ts +18 -7
  101. package/dist/managers/InteractionManager.d.ts.map +1 -1
  102. package/dist/managers/InteractionManager.js +154 -99
  103. package/dist/managers/InteractionManager.js.map +1 -1
  104. package/dist/managers/UniversalRenderingManager.d.ts +2 -1
  105. package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
  106. package/dist/managers/UniversalRenderingManager.js +7 -3
  107. package/dist/managers/UniversalRenderingManager.js.map +1 -1
  108. package/dist/react/CodeView.d.ts +13 -13
  109. package/dist/react/CodeView.d.ts.map +1 -1
  110. package/dist/react/CodeView.js +38 -29
  111. package/dist/react/CodeView.js.map +1 -1
  112. package/dist/react/EditContext.d.ts +20 -0
  113. package/dist/react/EditContext.d.ts.map +1 -0
  114. package/dist/react/EditContext.js +20 -0
  115. package/dist/react/EditContext.js.map +1 -0
  116. package/dist/react/File.d.ts +2 -1
  117. package/dist/react/File.d.ts.map +1 -1
  118. package/dist/react/File.js +3 -2
  119. package/dist/react/File.js.map +1 -1
  120. package/dist/react/FileDiff.d.ts +2 -2
  121. package/dist/react/FileDiff.d.ts.map +1 -1
  122. package/dist/react/FileDiff.js +3 -2
  123. package/dist/react/FileDiff.js.map +1 -1
  124. package/dist/react/MultiFileDiff.d.ts +2 -2
  125. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  126. package/dist/react/MultiFileDiff.js +3 -2
  127. package/dist/react/MultiFileDiff.js.map +1 -1
  128. package/dist/react/PatchDiff.d.ts +2 -2
  129. package/dist/react/PatchDiff.d.ts.map +1 -1
  130. package/dist/react/PatchDiff.js +3 -2
  131. package/dist/react/PatchDiff.js.map +1 -1
  132. package/dist/react/UnresolvedFile.d.ts +1 -1
  133. package/dist/react/UnresolvedFile.js.map +1 -1
  134. package/dist/react/index.d.ts +4 -4
  135. package/dist/react/index.js +3 -3
  136. package/dist/react/types.d.ts +9 -1
  137. package/dist/react/types.d.ts.map +1 -1
  138. package/dist/react/utils/useFileDiffInstance.d.ts +5 -3
  139. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  140. package/dist/react/utils/useFileDiffInstance.js +28 -27
  141. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  142. package/dist/react/utils/useFileInstance.d.ts +5 -3
  143. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  144. package/dist/react/utils/useFileInstance.js +29 -25
  145. package/dist/react/utils/useFileInstance.js.map +1 -1
  146. package/dist/react/utils/useUnresolvedFileInstance.js +3 -3
  147. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  148. package/dist/renderers/DiffHunksRenderer.d.ts +33 -1
  149. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  150. package/dist/renderers/DiffHunksRenderer.js +134 -21
  151. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  152. package/dist/renderers/FileRenderer.d.ts +2 -0
  153. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  154. package/dist/renderers/FileRenderer.js +33 -11
  155. package/dist/renderers/FileRenderer.js.map +1 -1
  156. package/dist/ssr/FileDiffReact.js +1 -1
  157. package/dist/ssr/index.d.ts +2 -2
  158. package/dist/ssr/preloadDiffs.js +1 -1
  159. package/dist/style.js +1 -1
  160. package/dist/types.d.ts +185 -42
  161. package/dist/types.d.ts.map +1 -1
  162. package/dist/utils/annotationHelpers.d.ts +20 -0
  163. package/dist/utils/annotationHelpers.d.ts.map +1 -0
  164. package/dist/utils/annotationHelpers.js +29 -0
  165. package/dist/utils/annotationHelpers.js.map +1 -0
  166. package/dist/utils/computeFileOffsets.d.ts.map +1 -1
  167. package/dist/utils/computeFileOffsets.js +34 -5
  168. package/dist/utils/computeFileOffsets.js.map +1 -1
  169. package/dist/utils/editSessionHunks.d.ts +66 -0
  170. package/dist/utils/editSessionHunks.d.ts.map +1 -0
  171. package/dist/utils/editSessionHunks.js +437 -0
  172. package/dist/utils/editSessionHunks.js.map +1 -0
  173. package/dist/utils/getHunkSideBoundaries.d.ts +7 -0
  174. package/dist/utils/getHunkSideBoundaries.d.ts.map +1 -0
  175. package/dist/utils/getHunkSideBoundaries.js +12 -0
  176. package/dist/utils/getHunkSideBoundaries.js.map +1 -0
  177. package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
  178. package/dist/utils/getTotalLineCountFromHunks.js +2 -1
  179. package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
  180. package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
  181. package/dist/utils/hydratePartialDiff.js +4 -3
  182. package/dist/utils/hydratePartialDiff.js.map +1 -1
  183. package/dist/utils/isGutterUtilityPath.d.ts +5 -0
  184. package/dist/utils/isGutterUtilityPath.d.ts.map +1 -0
  185. package/dist/utils/isGutterUtilityPath.js +12 -0
  186. package/dist/utils/isGutterUtilityPath.js.map +1 -0
  187. package/dist/utils/iterateOverDiff.d.ts.map +1 -1
  188. package/dist/utils/iterateOverDiff.js +17 -12
  189. package/dist/utils/iterateOverDiff.js.map +1 -1
  190. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  191. package/dist/utils/parseMergeConflictDiffFromFile.js +9 -6
  192. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  193. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  194. package/dist/utils/parsePatchFiles.js +6 -3
  195. package/dist/utils/parsePatchFiles.js.map +1 -1
  196. package/dist/utils/realignChangeContent.d.ts +33 -0
  197. package/dist/utils/realignChangeContent.d.ts.map +1 -0
  198. package/dist/utils/realignChangeContent.js +148 -0
  199. package/dist/utils/realignChangeContent.js.map +1 -0
  200. package/dist/utils/renderDiffWithHighlighter.js +1 -1
  201. package/dist/utils/resolveRegion.d.ts.map +1 -1
  202. package/dist/utils/resolveRegion.js +18 -2
  203. package/dist/utils/resolveRegion.js.map +1 -1
  204. package/dist/utils/updateDiffHunks.d.ts +8 -2
  205. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  206. package/dist/utils/updateDiffHunks.js +9 -7
  207. package/dist/utils/updateDiffHunks.js.map +1 -1
  208. package/dist/utils/virtualDiffLayout.d.ts +42 -2
  209. package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
  210. package/dist/utils/virtualDiffLayout.js +101 -7
  211. package/dist/utils/virtualDiffLayout.js.map +1 -1
  212. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  213. package/dist/worker/WorkerPoolManager.js +4 -2
  214. package/dist/worker/WorkerPoolManager.js.map +1 -1
  215. package/dist/worker/types.d.ts +4 -0
  216. package/dist/worker/types.d.ts.map +1 -1
  217. package/dist/worker/worker-portable.js +60 -20
  218. package/dist/worker/worker-portable.js.map +1 -1
  219. package/dist/worker/worker.js +61 -19
  220. package/dist/worker/worker.js.map +1 -1
  221. package/package.json +13 -8
  222. package/dist/editor/index.d.ts +0 -3
  223. package/dist/editor/index.js +0 -3
  224. package/dist/editor/tokenzier.d.ts.map +0 -1
  225. package/dist/editor/tokenzier.js.map +0 -1
  226. package/dist/react/EditorContext.d.ts +0 -15
  227. package/dist/react/EditorContext.d.ts.map +0 -1
  228. package/dist/react/EditorContext.js +0 -23
  229. package/dist/react/EditorContext.js.map +0 -1
@@ -1,36 +1,36 @@
1
1
  import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
2
2
  import { File } from "../../components/File.js";
3
3
  import { VirtualizedFile } from "../../components/VirtualizedFile.js";
4
- import { noopRender } from "../constants.js";
5
4
  import { useStableCallback } from "./useStableCallback.js";
5
+ import { useCreateEditor } from "../EditContext.js";
6
+ import { noopRender } from "../constants.js";
6
7
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
7
- import { useEditor } from "../EditorContext.js";
8
8
  import { useVirtualizer } from "../Virtualizer.js";
9
9
  import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
10
10
  //#region src/react/utils/useFileInstance.ts
11
- const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
- function useFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
11
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
+ function useFileInstance({ file, options, editorOptions, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit }) {
13
13
  const simpleVirtualizer = useVirtualizer();
14
14
  const controlledSelection = selectedLines !== void 0;
15
15
  const poolManager = useContext(WorkerPoolContext);
16
- const editor = useEditor();
16
+ const createEditor = useCreateEditor();
17
17
  const instanceRef = useRef(null);
18
18
  const ref = useStableCallback((node) => {
19
19
  if (node != null) {
20
20
  if (instanceRef.current != null) throw new Error("File: An instance should not already exist when a node is created");
21
21
  if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFile(mergeFileOptions({
22
22
  controlledSelection,
23
- contentEditable,
23
+ edit,
24
24
  hasCustomHeader,
25
- hasEditor: editor !== void 0,
25
+ hasEditor: createEditor !== void 0,
26
26
  hasGutterRenderUtility,
27
27
  options
28
28
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
29
29
  else instanceRef.current = new File(mergeFileOptions({
30
30
  controlledSelection,
31
- contentEditable,
31
+ edit,
32
32
  hasCustomHeader,
33
- hasEditor: editor !== void 0,
33
+ hasEditor: createEditor !== void 0,
34
34
  hasGutterRenderUtility,
35
35
  options
36
36
  }), !disableWorkerPool ? poolManager : void 0, true);
@@ -46,13 +46,13 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
46
46
  instanceRef.current = null;
47
47
  }
48
48
  });
49
- useIsometricEffect(() => {
49
+ useIsomorphicLayoutEffect(() => {
50
50
  if (instanceRef.current == null) return;
51
51
  const newOptions = mergeFileOptions({
52
52
  controlledSelection,
53
- contentEditable,
53
+ edit,
54
54
  hasCustomHeader,
55
- hasEditor: editor !== void 0,
55
+ hasEditor: createEditor !== void 0,
56
56
  hasGutterRenderUtility,
57
57
  options
58
58
  });
@@ -65,12 +65,19 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
65
65
  });
66
66
  if (selectedLines !== void 0) instanceRef.current.setSelectedLines(selectedLines);
67
67
  });
68
- useIsometricEffect(() => {
69
- if (contentEditable && instanceRef.current != null) {
70
- if (editor === void 0) throw new Error("File: Editor is not attached");
71
- return editor.edit(instanceRef.current);
68
+ useIsomorphicLayoutEffect(() => {
69
+ if (edit && instanceRef.current != null) {
70
+ if (createEditor === void 0) throw new Error("File: EditContext is not attached");
71
+ const editor = createEditor(editorOptions ?? {});
72
+ if (editor == null) throw new Error("File: EditProvider.createEditor must return an editor instance");
73
+ try {
74
+ return editor.edit(instanceRef.current);
75
+ } catch (error) {
76
+ editor.cleanUp();
77
+ throw error;
78
+ }
72
79
  }
73
- }, [contentEditable, editor]);
80
+ }, [edit]);
74
81
  return {
75
82
  ref,
76
83
  getHoveredLine: useCallback(() => {
@@ -78,10 +85,10 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
78
85
  }, [])
79
86
  };
80
87
  }
81
- function mergeFileOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
82
- const needsEditorOptions = contentEditable && hasEditor;
88
+ function mergeFileOptions({ options, controlledSelection, edit, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
89
+ const needsEditorOverrides = edit && hasEditor;
83
90
  const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
84
- if (!needsReactOverrides && !needsEditorOptions) return options;
91
+ if (!needsReactOverrides && !needsEditorOverrides) return options;
85
92
  let merged = { ...options };
86
93
  if (needsReactOverrides) merged = {
87
94
  ...merged,
@@ -89,12 +96,9 @@ function mergeFileOptions({ options, controlledSelection, contentEditable, hasCu
89
96
  renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
90
97
  renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
91
98
  };
92
- if (needsEditorOptions) merged = {
99
+ if (needsEditorOverrides) merged = {
93
100
  ...merged,
94
- useTokenTransformer: true,
95
- enableGutterUtility: false,
96
- enableLineSelection: false,
97
- lineHoverHighlight: "disabled"
101
+ useTokenTransformer: true
98
102
  };
99
103
  return merged;
100
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useEditor } from '../EditorContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n contentEditable: boolean;\n onChange?: (\n file: FileContents,\n lineAnnotations?: LineAnnotation<LAnnotation>[]\n ) => void;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<LAnnotation>();\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('File: Editor is not attached');\n }\n return editor.edit(instanceRef.current);\n }\n return undefined;\n }, [contentEditable, editor]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n contentEditable: boolean;\n hasEditor: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n const needsEditorOptions = contentEditable && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOptions) {\n return options;\n }\n\n let merged: FileOptions<LAnnotation> = { ...options };\n\n if (needsReactOverrides) {\n merged = {\n ...merged,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n }\n\n if (needsEditorOptions) {\n merged = {\n ...merged,\n useTokenTransformer: true,\n enableGutterUtility: false,\n enableLineSelection: false,\n lineHoverHighlight: 'disabled',\n };\n }\n\n return merged;\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAwB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,mBAC2D;CAC3D,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,SAAS,UAAuB;CACtC,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,SAA6B;EAC1D,IAAI,QAAQ,MAAM;GAChB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,mEACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MAAM,oDAAoD;GAEtE,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,yBAAyB;EACvB,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA,WAAW,WAAW,KAAA;GACtB;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBACnB,YAAY,QAAQ,SACpB,UACF;EACA,YAAY,QAAQ,WAAW,UAAU;EACzC,YAAiB,QAAQ,OAAO;GAAE;GAAM;GAAiB;EAAY,CAAC;EACtE,IAAI,kBAAkB,KAAA,GACpB,YAAY,QAAQ,iBAAiB,aAAa;CAEtD,CAAC;CAED,yBAAyB;EACvB,IAAI,mBAAmB,YAAY,WAAW,MAAM;GAClD,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,8BAA8B;GAEhD,OAAO,OAAO,KAAK,YAAY,OAAO;EACxC;CAEF,GAAG,CAAC,iBAAiB,MAAM,CAAC;CAO5B,OAAO;EAAE;EAAK,gBALS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CACuB;CAAE;AAC/B;AAWA,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,iBACA,WACA,0BAC2E;CAC3E,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,CAAC,oBAC3B,OAAO;CAGT,IAAI,SAAmC,EAAE,GAAG,QAAQ;CAEpD,IAAI,qBACF,SAAS;EACP,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;CAGF,IAAI,oBACF,SAAS;EACP,GAAG;EACH,qBAAqB;EACrB,qBAAqB;EACrB,qBAAqB;EACrB,oBAAoB;CACtB;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n editorOptions: EditorOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onChange?: (\n file: FileContents,\n lineAnnotations?: LineAnnotation<LAnnotation>[]\n ) => void;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n editorOptions,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation>();\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (edit && instanceRef.current != null) {\n if (createEditor === undefined) {\n throw new Error('File: EditContext is not attached');\n }\n const editor = createEditor(editorOptions ?? {});\n if (editor == null) {\n throw new Error(\n 'File: EditProvider.createEditor must return an editor instance'\n );\n }\n try {\n return editor.edit(instanceRef.current);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n }\n return undefined;\n }, [edit]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n edit: boolean;\n hasEditor: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n const needsEditorOverrides = edit && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOverrides) {\n return options;\n }\n\n let merged: FileOptions<LAnnotation> = { ...options };\n\n if (needsReactOverrides) {\n merged = {\n ...merged,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n }\n\n if (needsEditorOverrides) {\n merged = { ...merged, useTokenTransformer: true };\n }\n\n return merged;\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAyB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,eACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,QAC2D;CAC3D,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAA6B;CAClD,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,SAA6B;EAC1D,IAAI,QAAQ,MAAM;GAChB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,mEACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,iBAAiB,KAAA;IAC5B;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;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CAAC,sBAC3B,OAAO;CAGT,IAAI,SAAmC,EAAE,GAAG,QAAQ;CAEpD,IAAI,qBACF,SAAS;EACP,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;CAGF,IAAI,sBACF,SAAS;EAAE,GAAG;EAAQ,qBAAqB;CAAK;CAGlD,OAAO;AACT"}
@@ -1,12 +1,12 @@
1
1
  import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
2
2
  import { parseMergeConflictDiffFromFile } from "../../utils/parseMergeConflictDiffFromFile.js";
3
3
  import { UnresolvedFile } from "../../components/UnresolvedFile.js";
4
- import { noopRender } from "../constants.js";
5
4
  import { useStableCallback } from "./useStableCallback.js";
5
+ import { noopRender } from "../constants.js";
6
6
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
7
7
  import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
8
8
  //#region src/react/utils/useUnresolvedFileInstance.ts
9
- const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
9
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
10
10
  function useUnresolvedFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, hasConflictUtility, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }) {
11
11
  const [{ fileDiff, actions, markerRows }, setState] = useState(() => {
12
12
  const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(file, options?.maxContextLines);
@@ -55,7 +55,7 @@ function useUnresolvedFileInstance({ file, options, lineAnnotations, selectedLin
55
55
  instanceRef.current = null;
56
56
  }
57
57
  });
58
- useIsometricEffect(() => {
58
+ useIsomorphicLayoutEffect(() => {
59
59
  if (instanceRef.current == null) return;
60
60
  const instance = instanceRef.current;
61
61
  const newOptions = mergeUnresolvedOptions({
@@ -1 +1 @@
1
- {"version":3,"file":"useUnresolvedFileInstance.js","names":["UnresolvedFileClass"],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n UnresolvedFile,\n UnresolvedFile as UnresolvedFileClass,\n type UnresolvedFileOptions,\n} from '../../components/UnresolvedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n MergeConflictActionPayload,\n MergeConflictMarkerRow,\n SelectedLineRange,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport {\n type MergeConflictDiffAction,\n parseMergeConflictDiffFromFile,\n} from '../../utils/parseMergeConflictDiffFromFile';\nimport { noopRender } from '../constants';\nimport type { UnresolvedFileReactOptions } from '../UnresolvedFile';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseUnresolvedFileInstanceProps<LAnnotation> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseUnresolvedFileInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance(): UnresolvedFile<LAnnotation> | undefined;\n}\n\nexport function useUnresolvedFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation> {\n const [{ fileDiff, actions, markerRows }, setState] = useState(() => {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n return { fileDiff, actions, markerRows };\n });\n // UnresolvedFile is intentionally uncontrolled in React. Keep an internal\n // source-of-truth file so sequential conflict actions apply to the latest\n // resolved contents rather than the initial prop value.\n const onMergeConflictAction = useStableCallback(\n (\n payload: MergeConflictActionPayload,\n instance: UnresolvedFile<LAnnotation>\n ) => {\n setState((prevState) => {\n const { fileDiff, actions, markerRows } =\n instance.resolveConflict(\n payload.conflict.conflictIndex,\n payload.resolution,\n prevState.fileDiff\n ) ?? {};\n if (fileDiff == null || actions == null || markerRows == null) {\n return prevState;\n } else {\n return { fileDiff, actions, markerRows };\n }\n });\n }\n );\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<UnresolvedFileClass<LAnnotation> | null>(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useUnresolvedFileInstance: An instance should not already exist when a node is created'\n );\n }\n instanceRef.current = new UnresolvedFileClass(\n mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n void instanceRef.current.hydrate({\n fileDiff,\n actions,\n markerRows,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useUnresolvedFileInstance: A UnresolvedFile instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const instance = instanceRef.current;\n const newOptions = mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n fileDiff,\n actions,\n markerRows,\n lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n const getInstance = useCallback(() => {\n return instanceRef.current ?? undefined;\n }, []);\n\n return { ref, getHoveredLine, fileDiff, actions, markerRows, getInstance };\n}\n\ninterface MergeUnresolvedOptionsProps<LAnnotation> {\n options: UnresolvedFileReactOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n onMergeConflictAction: UnresolvedFileOptions<LAnnotation>['onMergeConflictAction'];\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeUnresolvedOptions<LAnnotation>({\n options,\n controlledSelection,\n onMergeConflictAction,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeUnresolvedOptionsProps<LAnnotation>): UnresolvedFileOptions<LAnnotation> {\n return {\n ...options,\n controlledSelection,\n onMergeConflictAction,\n hunkSeparators:\n options?.hunkSeparators === 'custom'\n ? noopRender\n : options?.hunkSeparators,\n // Add a placeholder type for the custom render\n mergeConflictActionsType:\n hasConflictUtility || options?.mergeConflictActionsType === 'custom'\n ? noopRender\n : options?.mergeConflictActionsType,\n renderCustomHeader: hasCustomHeader ? noopRender : undefined,\n renderGutterUtility: hasGutterRenderUtility ? noopRender : undefined,\n };\n}\n"],"mappings":";;;;;;;;AAiCA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAuB9C,SAAgB,0BAAuC,EACrD,MACA,SACA,iBACA,eACA,iBACA,oBACA,wBACA,iBACA,qBAC4F;CAC5F,MAAM,CAAC,EAAE,UAAU,SAAS,cAAc,YAAY,eAAe;EACnE,M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YD,OAAO;EAAE;EAAK,gBAVS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAMuB;EAAG;EAAU;EAAS;EAAY,aAJzC,kBAAkB;GACpC,OAAO,YAAY,WAAW,KAAA;EAChC,GAAG,CAAC,CAEmE;CAAE;AAC3E;AAWA,SAAS,uBAAoC,EAC3C,SACA,qBACA,uBACA,oBACA,iBACA,0BAC+E;CAC/E,OAAO;EACL,GAAG;EACH;EACA;EACA,gBACE,SAAS,mBAAmB,WACxB,aACA,SAAS;EAEf,0BACE,sBAAsB,SAAS,6BAA6B,WACxD,aACA,SAAS;EACf,oBAAoB,kBAAkB,aAAa,KAAA;EACnD,qBAAqB,yBAAyB,aAAa,KAAA;CAC7D;AACF"}
1
+ {"version":3,"file":"useUnresolvedFileInstance.js","names":["UnresolvedFileClass"],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n UnresolvedFile,\n UnresolvedFile as UnresolvedFileClass,\n type UnresolvedFileOptions,\n} from '../../components/UnresolvedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n MergeConflictActionPayload,\n MergeConflictMarkerRow,\n SelectedLineRange,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport {\n type MergeConflictDiffAction,\n parseMergeConflictDiffFromFile,\n} from '../../utils/parseMergeConflictDiffFromFile';\nimport { noopRender } from '../constants';\nimport type { UnresolvedFileReactOptions } from '../UnresolvedFile';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseUnresolvedFileInstanceProps<LAnnotation> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseUnresolvedFileInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance(): UnresolvedFile<LAnnotation> | undefined;\n}\n\nexport function useUnresolvedFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation> {\n const [{ fileDiff, actions, markerRows }, setState] = useState(() => {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n return { fileDiff, actions, markerRows };\n });\n // UnresolvedFile is intentionally uncontrolled in React. Keep an internal\n // source-of-truth file so sequential conflict actions apply to the latest\n // resolved contents rather than the initial prop value.\n const onMergeConflictAction = useStableCallback(\n (\n payload: MergeConflictActionPayload,\n instance: UnresolvedFile<LAnnotation>\n ) => {\n setState((prevState) => {\n const { fileDiff, actions, markerRows } =\n instance.resolveConflict(\n payload.conflict.conflictIndex,\n payload.resolution,\n prevState.fileDiff\n ) ?? {};\n if (fileDiff == null || actions == null || markerRows == null) {\n return prevState;\n } else {\n return { fileDiff, actions, markerRows };\n }\n });\n }\n );\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<UnresolvedFileClass<LAnnotation> | null>(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useUnresolvedFileInstance: An instance should not already exist when a node is created'\n );\n }\n instanceRef.current = new UnresolvedFileClass(\n mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n void instanceRef.current.hydrate({\n fileDiff,\n actions,\n markerRows,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useUnresolvedFileInstance: A UnresolvedFile instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (instanceRef.current == null) return;\n const instance = instanceRef.current;\n const newOptions = mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n fileDiff,\n actions,\n markerRows,\n lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n const getInstance = useCallback(() => {\n return instanceRef.current ?? undefined;\n }, []);\n\n return { ref, getHoveredLine, fileDiff, actions, markerRows, getInstance };\n}\n\ninterface MergeUnresolvedOptionsProps<LAnnotation> {\n options: UnresolvedFileReactOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n onMergeConflictAction: UnresolvedFileOptions<LAnnotation>['onMergeConflictAction'];\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeUnresolvedOptions<LAnnotation>({\n options,\n controlledSelection,\n onMergeConflictAction,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeUnresolvedOptionsProps<LAnnotation>): UnresolvedFileOptions<LAnnotation> {\n return {\n ...options,\n controlledSelection,\n onMergeConflictAction,\n hunkSeparators:\n options?.hunkSeparators === 'custom'\n ? noopRender\n : options?.hunkSeparators,\n // Add a placeholder type for the custom render\n mergeConflictActionsType:\n hasConflictUtility || options?.mergeConflictActionsType === 'custom'\n ? noopRender\n : options?.mergeConflictActionsType,\n renderCustomHeader: hasCustomHeader ? noopRender : undefined,\n renderGutterUtility: hasGutterRenderUtility ? noopRender : undefined,\n };\n}\n"],"mappings":";;;;;;;;AAiCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAuB9C,SAAgB,0BAAuC,EACrD,MACA,SACA,iBACA,eACA,iBACA,oBACA,wBACA,iBACA,qBAC4F;CAC5F,MAAM,CAAC,EAAE,UAAU,SAAS,cAAc,YAAY,eAAe;EACnE,MAAM,EAAE,UAAU,SAAS,eAAe,+BACxC,MACA,SAAS,eACX;EACA,OAAO;GAAE;GAAU;GAAS;EAAW;CACzC,CAAC;CAID,MAAM,wBAAwB,mBAE1B,SACA,aACG;EACH,UAAU,cAAc;GACtB,MAAM,EAAE,UAAU,SAAS,eACzB,SAAS,gBACP,QAAQ,SAAS,eACjB,QAAQ,YACR,UAAU,QACZ,KAAK,CAAC;GACR,IAAI,YAAY,QAAQ,WAAW,QAAQ,cAAc,MACvD,OAAO;QAEP,OAAO;IAAE;IAAU;IAAS;GAAW;EAE3C,CAAC;CACH,CACF;CACA,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,cAAc,OAAgD,IAAI;CACxE,MAAM,MAAM,mBAAmB,kBAAsC;EACnE,IAAI,iBAAiB,MAAM;GACzB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,wFACF;GAEF,YAAY,UAAU,IAAIA,eACxB,uBAAuB;IACrB;IACA;IACA;IACA;IACA;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GACA,YAAiB,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;IACA;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,mFACF;GAEF,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,gCAAgC;EAC9B,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,WAAW,YAAY;EAC7B,MAAM,aAAa,uBAAuB;GACxC;GACA;GACA;GACA;GACA;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,UAAU;EACjE,SAAS,WAAW,UAAU;EAC9B,SAAc,OAAO;GACnB;GACA;GACA;GACA;GACA;EACF,CAAC;EACD,IAAI,kBAAkB,KAAA,GACpB,SAAS,iBAAiB,aAAa;CAE3C,CAAC;CAYD,OAAO;EAAE;EAAK,gBAVS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAMuB;EAAG;EAAU;EAAS;EAAY,aAJzC,kBAAkB;GACpC,OAAO,YAAY,WAAW,KAAA;EAChC,GAAG,CAAC,CAEmE;CAAE;AAC3E;AAWA,SAAS,uBAAoC,EAC3C,SACA,qBACA,uBACA,oBACA,iBACA,0BAC+E;CAC/E,OAAO;EACL,GAAG;EACH;EACA;EACA,gBACE,SAAS,mBAAmB,WACxB,aACA,SAAS;EAEf,0BACE,sBAAsB,SAAS,6BAA6B,WACxD,aACA,SAAS;EACf,oBAAoB,kBAAkB,aAAa,KAAA;EACnD,qBAAqB,yBAAyB,aAAa,KAAA;CAC7D;AACF"}
@@ -81,9 +81,30 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
81
81
  private additionAnnotations;
82
82
  private computedLang;
83
83
  private renderCache;
84
+ private editSessionActive;
84
85
  constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);
85
86
  cleanUp(): void;
86
87
  recycle(): void;
88
+ /**
89
+ * Enter edit-session mode: hunk updates preserve the current region
90
+ * skeleton instead of recomputing hunks. Called on every editor attach,
91
+ * including a re-attach after recycle.
92
+ */
93
+ beginEditSession(): void;
94
+ /** Leave edit-session mode. The exit recompute is the host's concern. */
95
+ endEditSession(): void;
96
+ /**
97
+ * Re-highlights the current diff in the background and swaps the fresh
98
+ * result in (with a re-render) once it completes. Needed after an edit
99
+ * session's exit recompute: session passes plain-fill shifted lines in the
100
+ * cached result, and the recompute mutates the diff in place (same object,
101
+ * same cacheKey), so identity/cacheKey checks would otherwise treat the
102
+ * stale highlight as current forever. The current result — content-correct,
103
+ * mostly highlighted — keeps rendering until the fresh one lands, so no
104
+ * interim paint drops highlighting.
105
+ */
106
+ refreshHighlightedResult(): Promise<void>;
107
+ private applyRefreshedResult;
87
108
  get diffCache(): FileDiffMetadata | undefined;
88
109
  clearRenderCache(): void;
89
110
  setOptions(options: DiffHunksRendererOptions): void;
@@ -91,9 +112,20 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
91
112
  expandHunk(index: number, direction: ExpansionDirections, expansionLineCount?: number): void;
92
113
  getExpandedHunk(hunkIndex: number): HunkExpansionRegion;
93
114
  getExpandedHunksMap(): Map<number, HunkExpansionRegion>;
115
+ /** Replace the whole expansion map (session-exit expansion remapping). */
116
+ setExpandedHunksMap(expandedHunks: Map<number, HunkExpansionRegion>): void;
94
117
  setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;
95
- updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light'): void;
118
+ /**
119
+ * Returns true when a session-mode pass changed the region skeleton itself
120
+ * (a gap edit synthesized or merged regions), which changes the rendered
121
+ * row set without a line-count change — the host must escalate to a full
122
+ * re-render instead of its cheap refresh path.
123
+ */
124
+ updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', lineCountChangeInFlight?: boolean): boolean;
125
+ private applyExpansionRemap;
96
126
  applyDocumentChange(textDocument: DiffsTextDocument): void;
127
+ private applySessionDocumentChange;
128
+ private markEditSessionPass;
97
129
  protected getUnifiedLineDecoration({
98
130
  lineType
99
131
  }: UnifiedLineDecorationProps): LineDecoration;
@@ -1 +1 @@
1
- {"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;UAiIiB,wBAAA,SAAiC,eAAe;EAC/D,gBAAA,GAAmB,oBAAA;AAAA;AAAA,UAGJ,oCAAA,SAA6C,IAAA,CAC5D,2BAAA;EAGA,gBAAA,EAAkB,oBAAA;AAAA;AAAA,UAGH,0BAAA;EACf,IAAA;EACA,QAAA,EAAU,SAAS;EACnB,iBAAA;EACA,iBAAA;AAAA;AAAA,UAGe,wBAAA;EACf,IAAA;EACA,IAAA;EACA,SAAA;AAAA;AAAA,UAGe,cAAA;EACf,cAAA,EAAgB,SAAA;EAChB,gBAAA,GAAmB,UAAA;EACnB,iBAAA,GAAoB,UAAA;AAAA;AAAA,UAUL,mBAAA;EACf,IAAA;EACA,SAAA;EACA,SAAA;EACA,gBAAA;EACA,cAAA;EACA,YAAA,GAAe,gBAAA;EACf,YAAA,GAAe,gBAAgB;AAAA;AAAA,UAGhB,WAAA;EACf,OAAA,EAAS,OAAA;EACT,MAAA,EAAQ,OAAW;AAAA;AAAA,UAGJ,gBAAA;EACf,QAAA,EAAU,WAAA;EACV,QAAA,EAAU,WAAW;AAAA;AAAA,UAGN,2BAAA;EACf,MAAA,GAAS,WAAA;EACT,KAAA,GAAQ,WAAW;AAAA;AAAA,UAGJ,yBAAA;EACf,MAAA,GAAS,gBAAA;EACT,KAAA,GAAQ,gBAAgB;AAAA;AAAA,UAGT,iBAAA;EACf,gBAAA,EAAkB,cAAA;EAClB,iBAAA,EAAmB,cAAA;EACnB,kBAAA,EAAoB,cAAA;EACpB,mBAAA,EAAqB,cAAA;EACrB,kBAAA,EAAoB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N,WAAA,GAAa,WAAA,GACZ,OAAA,CAAQ,iBAAA;EAAA,UAKD,gBAAA,CACR,KAAA,WACA,UAAA,UACA,gBAAA,GAAmB,mBAAA,GAClB,OAAA;EAAA,QAeW,cAAA;EAAA,QAyBN,yBAAA;EAeD,kBAAA,CACL,IAAA,EAAM,gBAAA,EACN,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,iBAAA,EACT,WAAA;EAAA,QA2BM,4BAAA;EAAA,QAWA,yBAAA;EAaD,gBAAA,CAAiB,KAAA;EAAA,QAIhB,oBAAA;EAAA,QAIA,iBAAA;EAgjBD,aAAA,CACL,IAAA,yCACA,MAAA,EAAQ,iBAAA,GACP,cAAA;EAyBI,aAAA,CACL,MAAA,EAAQ,iBAAA,EACR,QAAA,GAAU,cAAA,KACT,OAAA;EAkDI,cAAA,CACL,MAAA,EAAQ,iBAAA,EACR,YAAA,GAAc,cAAA;EAKT,iBAAA,CACL,QAAA,EAAU,cAAA,IACV,UAAA;EAAA,QAqBM,wBAAA;EAAA,QAiEA,cAAA;EAAA,QA+DA,YAAA;AAAA"}
@@ -1,4 +1,8 @@
1
1
  import { DEFAULT_EXPANDED_REGION, DEFAULT_RENDER_RANGE, DEFAULT_THEMES, DEFAULT_TOKENIZE_MAX_LENGTH } from "../constants.js";
2
+ import { cleanLastNewline } from "../utils/cleanLastNewline.js";
3
+ import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
4
+ import { recomputeDiffHunksForEdit, recomputeEmptyDocumentDiff, recomputeTopAlignedAdditionDiff, shouldTopAlignAdditionRecompute, updateDiffHunks } from "../utils/updateDiffHunks.js";
5
+ import { applySessionChangedLines, rebuildSessionHunks, remapExpandedHunksForRegionChange } from "../utils/editSessionHunks.js";
2
6
  import { getFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
3
7
  import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
4
8
  import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
@@ -15,9 +19,7 @@ import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
15
19
  import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
16
20
  import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
17
21
  import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
18
- import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
19
22
  import { iterateOverDiff } from "../utils/iterateOverDiff.js";
20
- import { cleanLastNewline } from "../utils/cleanLastNewline.js";
21
23
  import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
22
24
  import { createEmptyRowBuffer } from "../utils/createEmptyRowBuffer.js";
23
25
  import { createNoNewlineElement } from "../utils/createNoNewlineElement.js";
@@ -27,7 +29,6 @@ import { getTotalLineCountFromHunks } from "../utils/getTotalLineCountFromHunks.
27
29
  import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
28
30
  import { isDiffPlainText } from "../utils/isDiffPlainText.js";
29
31
  import { renderDiffWithHighlighter } from "../utils/renderDiffWithHighlighter.js";
30
- import { recomputeDiffHunksForEdit, recomputeEmptyDocumentDiff, updateDiffHunks } from "../utils/updateDiffHunks.js";
31
32
  import { toHtml } from "hast-util-to-html";
32
33
  //#region src/renderers/DiffHunksRenderer.ts
33
34
  let instanceId = -1;
@@ -43,6 +44,7 @@ var DiffHunksRenderer = class {
43
44
  additionAnnotations = {};
44
45
  computedLang = "text";
45
46
  renderCache;
47
+ editSessionActive = false;
46
48
  constructor(options = { theme: DEFAULT_THEMES }, onRenderUpdate, workerManager) {
47
49
  this.options = options;
48
50
  this.onRenderUpdate = onRenderUpdate;
@@ -62,6 +64,55 @@ var DiffHunksRenderer = class {
62
64
  this.additionAnnotations = {};
63
65
  this.deletionAnnotations = {};
64
66
  this.workerManager?.cleanUpTasks(this);
67
+ this.endEditSession();
68
+ }
69
+ /**
70
+ * Enter edit-session mode: hunk updates preserve the current region
71
+ * skeleton instead of recomputing hunks. Called on every editor attach,
72
+ * including a re-attach after recycle.
73
+ */
74
+ beginEditSession() {
75
+ this.editSessionActive = true;
76
+ }
77
+ /** Leave edit-session mode. The exit recompute is the host's concern. */
78
+ endEditSession() {
79
+ this.editSessionActive = false;
80
+ }
81
+ /**
82
+ * Re-highlights the current diff in the background and swaps the fresh
83
+ * result in (with a re-render) once it completes. Needed after an edit
84
+ * session's exit recompute: session passes plain-fill shifted lines in the
85
+ * cached result, and the recompute mutates the diff in place (same object,
86
+ * same cacheKey), so identity/cacheKey checks would otherwise treat the
87
+ * stale highlight as current forever. The current result — content-correct,
88
+ * mostly highlighted — keeps rendering until the fresh one lands, so no
89
+ * interim paint drops highlighting.
90
+ */
91
+ refreshHighlightedResult() {
92
+ const { renderCache } = this;
93
+ if (renderCache == null || isDiffPlainText(renderCache.diff) || isDiffMassive(renderCache.diff, this.getTokenizeMaxLength())) return Promise.resolve();
94
+ const { diff } = renderCache;
95
+ const { workerManager } = this;
96
+ if (workerManager?.isWorkingPool() === true && diff.cacheKey != null) {
97
+ workerManager.evictDiffFromCache(diff.cacheKey);
98
+ return workerManager.primeDiffHighlightCache(diff).then(() => {
99
+ this.applyRefreshedResult(diff, workerManager.getDiffResultCache(diff));
100
+ }).catch((error) => this.onHighlightError(error));
101
+ }
102
+ return this.asyncHighlight(diff).then((fresh) => this.applyRefreshedResult(diff, fresh)).catch((error) => this.onHighlightError(error));
103
+ }
104
+ applyRefreshedResult(diff, fresh) {
105
+ if (fresh == null || this.renderCache == null || this.renderCache.diff !== diff || this.editSessionActive) return;
106
+ const { options } = this.getRenderOptions(diff);
107
+ if (!areDiffRenderOptionsEqual(options, fresh.options)) return;
108
+ this.renderCache = {
109
+ diff,
110
+ options: fresh.options,
111
+ highlighted: true,
112
+ result: fresh.result,
113
+ renderRange: void 0
114
+ };
115
+ this.onRenderUpdate?.();
65
116
  }
66
117
  get diffCache() {
67
118
  return this.renderCache?.diff ?? this.diff;
@@ -96,6 +147,10 @@ var DiffHunksRenderer = class {
96
147
  getExpandedHunksMap() {
97
148
  return this.expandedHunks;
98
149
  }
150
+ /** Replace the whole expansion map (session-exit expansion remapping). */
151
+ setExpandedHunksMap(expandedHunks) {
152
+ this.expandedHunks = expandedHunks;
153
+ }
99
154
  setLineAnnotations(lineAnnotations) {
100
155
  this.additionAnnotations = {};
101
156
  this.deletionAnnotations = {};
@@ -111,13 +166,20 @@ var DiffHunksRenderer = class {
111
166
  arr.push(annotation);
112
167
  }
113
168
  }
114
- updateRenderCache(dirtyLines, themeType) {
115
- if (this.renderCache == null) return;
169
+ /**
170
+ * Returns true when a session-mode pass changed the region skeleton itself
171
+ * (a gap edit synthesized or merged regions), which changes the rendered
172
+ * row set without a line-count change — the host must escalate to a full
173
+ * re-render instead of its cheap refresh path.
174
+ */
175
+ updateRenderCache(dirtyLines, themeType, lineCountChangeInFlight = false) {
176
+ if (this.renderCache == null) return false;
116
177
  const { result, diff } = this.renderCache;
117
- if (result == null) return;
178
+ if (result == null) return false;
118
179
  if (diff.isPartial) throw new Error("Could not update render cache for partial diff");
119
180
  const hastLines = result.code.additionLines;
120
181
  const changedAdditionLines = [];
182
+ const previousAdditionLines = /* @__PURE__ */ new Map();
121
183
  for (const [line, tokens] of dirtyLines) {
122
184
  const prevProps = hastLines[line]?.properties ?? {};
123
185
  const lineText = tokens.map((a) => a[2]).join("");
@@ -126,7 +188,10 @@ var DiffHunksRenderer = class {
126
188
  const prevText = cleanLastNewline(prevLine);
127
189
  if (canSyncDiffLine) {
128
190
  diff.additionLines[line] = applyLineTextWithNewline(prevLine, lineText);
129
- if (prevText !== lineText) changedAdditionLines.push(line);
191
+ if (prevText !== lineText) {
192
+ changedAdditionLines.push(line);
193
+ previousAdditionLines.set(line, prevLine);
194
+ }
130
195
  }
131
196
  hastLines[line] = {
132
197
  type: "element",
@@ -154,7 +219,7 @@ var DiffHunksRenderer = class {
154
219
  tagName: "span",
155
220
  properties: {
156
221
  "data-char": char,
157
- style: `--diffs-token-${themeType}:${fg};`
222
+ style: `color:${fg};`
158
223
  },
159
224
  children: [{
160
225
  type: "text",
@@ -164,26 +229,59 @@ var DiffHunksRenderer = class {
164
229
  })
165
230
  };
166
231
  }
167
- if (changedAdditionLines.length > 0) Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
232
+ let regionsChanged = false;
233
+ if (changedAdditionLines.length > 0) if (this.editSessionActive && !diff.isPartial) {
234
+ if (!lineCountChangeInFlight) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
235
+ Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
236
+ this.markEditSessionPass(diff);
237
+ regionsChanged = true;
238
+ } else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
239
+ Object.assign(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
240
+ this.markEditSessionPass(diff);
241
+ regionsChanged = true;
242
+ } else {
243
+ const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
244
+ this.applyExpansionRemap(change);
245
+ regionsChanged = change != null;
246
+ }
247
+ } else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
168
248
  result.baseThemeType = themeType;
169
249
  this.renderCache.isDirty = true;
250
+ return regionsChanged;
251
+ }
252
+ applyExpansionRemap(change) {
253
+ if (change != null) this.expandedHunks = remapExpandedHunksForRegionChange(this.expandedHunks, change);
170
254
  }
171
255
  applyDocumentChange(textDocument) {
172
256
  if (this.renderCache == null) return;
173
257
  const { diff, result } = this.renderCache;
174
258
  if (result == null) return;
175
- diff.additionLines = getEditorDocumentLines(textDocument, diff.additionLines);
176
- const newLength = diff.additionLines.length;
177
- const additionHastLines = result.code.additionLines;
178
- const prevLen = additionHastLines.length;
179
- if (newLength < prevLen) additionHastLines.length = newLength;
180
- for (let i = prevLen; i < newLength; i++) additionHastLines[i] ??= createPlainAdditionLineElement(i, textDocument);
181
- if (!diff.isPartial) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
259
+ if (diff.isPartial) throw new Error("Could not apply document change for partial diff");
260
+ const { additionLines: previousAdditionLines } = diff;
261
+ diff.additionLines = getEditorDocumentLines(textDocument, previousAdditionLines);
262
+ result.code.additionLines = realignAdditionHastLines(previousAdditionLines, diff.additionLines, result.code.additionLines, textDocument);
263
+ if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
182
264
  Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
183
- additionHastLines[0] = createPlainAdditionLineElement(0, textDocument);
184
- } else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
265
+ result.code.additionLines[0] = createPlainAdditionLineElement(0, textDocument);
266
+ this.markEditSessionPass(diff);
267
+ } else if (this.editSessionActive) this.applySessionDocumentChange(diff);
268
+ else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
185
269
  this.renderCache.isDirty = true;
186
270
  }
271
+ applySessionDocumentChange(diff) {
272
+ const { parseDiffOptions } = this.options;
273
+ const rawLines = diff.additionLines;
274
+ if (shouldTopAlignAdditionRecompute(diff, rawLines)) {
275
+ Object.assign(diff, recomputeTopAlignedAdditionDiff(diff, rawLines, parseDiffOptions));
276
+ this.markEditSessionPass(diff);
277
+ return;
278
+ }
279
+ this.applyExpansionRemap(rebuildSessionHunks(diff, parseDiffOptions));
280
+ }
281
+ markEditSessionPass(diff) {
282
+ if (!this.editSessionActive) return;
283
+ diff.editSessionDirty = true;
284
+ }
187
285
  getUnifiedLineDecoration({ lineType }) {
188
286
  return {
189
287
  gutterLineType: lineType,
@@ -304,7 +402,9 @@ var DiffHunksRenderer = class {
304
402
  const newContent = !areDiffTargetsEqual(diff, this.renderCache.diff);
305
403
  const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
306
404
  if (this.workerManager?.isWorkingPool() === true) {
307
- if (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange)) {
405
+ const highlightPending = this.renderCache.result == null && this.renderCache.highlighted && !forcePlainText && !newContent && isDefaultRenderRange(renderRange);
406
+ if (highlightPending) this.renderCache.highlightPending = true;
407
+ if (!highlightPending && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
308
408
  this.renderCache.diff = diff;
309
409
  this.renderCache.options = options;
310
410
  this.renderCache.highlighted = false;
@@ -373,7 +473,7 @@ var DiffHunksRenderer = class {
373
473
  }
374
474
  onHighlightSuccess(diff, result, options, highlighted = true) {
375
475
  if (this.renderCache == null) return;
376
- const triggerRenderUpdate = !this.renderCache.highlighted || !areDiffRenderOptionsEqual(this.renderCache.options, options) || !areDiffTargetsEqual(this.renderCache.diff, diff);
476
+ const triggerRenderUpdate = this.renderCache.highlightPending === true || !this.renderCache.highlighted || !areDiffRenderOptionsEqual(this.renderCache.options, options) || !areDiffTargetsEqual(this.renderCache.diff, diff);
377
477
  this.renderCache = {
378
478
  diff,
379
479
  options,
@@ -574,7 +674,7 @@ var DiffHunksRenderer = class {
574
674
  if (pendingSplitContext.side != null && pendingSplitContext.side !== missingSide) pendingSplitContext.flush();
575
675
  pendingSplitContext.side = missingSide;
576
676
  pendingSplitContext.increment();
577
- }
677
+ } else if (type === "change") pendingSplitContext.flush();
578
678
  const annotationSpans = this.getAnnotations("split", deletionLine?.lineNumber, additionLine?.lineNumber, hunkIndex, lineIndex);
579
679
  if (annotationSpans != null && pendingSplitContext.size > 0) pendingSplitContext.flush();
580
680
  if (deletionLine != null) {
@@ -972,6 +1072,19 @@ function withContentProperties(lineNode, contentProperties, extendProperties) {
972
1072
  }
973
1073
  };
974
1074
  }
1075
+ function realignAdditionHastLines(previousLines, nextLines, hastLines, textDocument) {
1076
+ const maxShared = Math.min(previousLines.length, nextLines.length);
1077
+ let prefix = 0;
1078
+ while (prefix < maxShared && previousLines[prefix] === nextLines[prefix]) prefix++;
1079
+ let suffix = 0;
1080
+ while (suffix < maxShared - prefix && previousLines[previousLines.length - 1 - suffix] === nextLines[nextLines.length - 1 - suffix]) suffix++;
1081
+ const realigned = new Array(nextLines.length);
1082
+ for (let index = 0; index < prefix; index++) realigned[index] = hastLines[index];
1083
+ for (let offset = 0; offset < suffix; offset++) realigned[nextLines.length - 1 - offset] = hastLines[previousLines.length - 1 - offset];
1084
+ for (let index = previousLines.length; index < nextLines.length; index++) realigned[index] ??= hastLines[index];
1085
+ for (let index = prefix; index < nextLines.length - suffix; index++) realigned[index] ??= createPlainAdditionLineElement(index, textDocument);
1086
+ return realigned;
1087
+ }
975
1088
  function createPlainAdditionLineElement(lineIndex, textDocument) {
976
1089
  return {
977
1090
  type: "element",