@pierre/diffs 1.3.0-rc.1 → 1.3.0-rc.2

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 (61) hide show
  1. package/README.md +9 -0
  2. package/dist/components/CodeView.d.ts +0 -1
  3. package/dist/components/CodeView.d.ts.map +1 -1
  4. package/dist/components/CodeView.js +2 -17
  5. package/dist/components/CodeView.js.map +1 -1
  6. package/dist/components/File.d.ts +3 -1
  7. package/dist/components/File.d.ts.map +1 -1
  8. package/dist/components/File.js +6 -3
  9. package/dist/components/File.js.map +1 -1
  10. package/dist/components/FileDiff.d.ts +4 -1
  11. package/dist/components/FileDiff.d.ts.map +1 -1
  12. package/dist/components/FileDiff.js +5 -3
  13. package/dist/components/FileDiff.js.map +1 -1
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +7 -2
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/editor/editor.d.ts.map +1 -1
  18. package/dist/editor/editor.js +6 -10
  19. package/dist/editor/editor.js.map +1 -1
  20. package/dist/editor/tokenizer.d.ts.map +1 -1
  21. package/dist/editor/tokenizer.js +106 -51
  22. package/dist/editor/tokenizer.js.map +1 -1
  23. package/dist/react/CodeView.js +1 -1
  24. package/dist/react/utils/useFileDiffInstance.js +6 -17
  25. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  26. package/dist/react/utils/useFileInstance.js +5 -19
  27. package/dist/react/utils/useFileInstance.js.map +1 -1
  28. package/dist/react/utils/useUnresolvedFileInstance.js +1 -1
  29. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  30. package/dist/renderers/DiffHunksRenderer.d.ts +10 -2
  31. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  32. package/dist/renderers/DiffHunksRenderer.js +36 -11
  33. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  34. package/dist/renderers/FileRenderer.d.ts +18 -1
  35. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  36. package/dist/renderers/FileRenderer.js +86 -18
  37. package/dist/renderers/FileRenderer.js.map +1 -1
  38. package/dist/ssr/FileDiffReact.js +1 -1
  39. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  40. package/dist/ssr/preloadDiffs.js +2 -0
  41. package/dist/ssr/preloadDiffs.js.map +1 -1
  42. package/dist/ssr/preloadFile.d.ts.map +1 -1
  43. package/dist/ssr/preloadFile.js +2 -0
  44. package/dist/ssr/preloadFile.js.map +1 -1
  45. package/dist/types.d.ts +13 -6
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
  48. package/dist/utils/getDiffHunksRendererOptions.js +2 -1
  49. package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
  50. package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
  51. package/dist/utils/getFileRendererOptions.js +2 -1
  52. package/dist/utils/getFileRendererOptions.js.map +1 -1
  53. package/dist/utils/shouldUseTokenTransformer.d.ts +7 -3
  54. package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
  55. package/dist/utils/shouldUseTokenTransformer.js +1 -1
  56. package/dist/utils/shouldUseTokenTransformer.js.map +1 -1
  57. package/dist/worker/WorkerPoolManager.d.ts +2 -1
  58. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  59. package/dist/worker/WorkerPoolManager.js +3 -0
  60. package/dist/worker/WorkerPoolManager.js.map +1 -1
  61. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\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 UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n editorOptions: EditorOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<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}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n editorOptions,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation>();\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\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 FileDiff(\n mergeFileDiffOptions({\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 fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (edit && instanceRef.current != null) {\n if (createEditor === undefined) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n const editor = createEditor(editorOptions ?? {});\n if (editor == null) {\n throw new Error(\n 'FileDiff: 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<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {\n ref,\n getHoveredLine,\n };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n edit: boolean;\n hasEditor: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsEditorOverrides = edit && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOverrides) {\n return options;\n }\n\n return {\n ...options,\n ...(needsReactOverrides\n ? {\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n }\n : null),\n ...(needsEditorOverrides ? { useTokenTransformer: true } : null),\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAqB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,eACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,QACmE;CACnE,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,kBAAsC;EACnE,IAAI,iBAAiB,MAAM;GACzB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,kFACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,iBAAiB,KAAA;IAC5B;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,SACxB,qBAAqB;I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AC3B,OAAO;CAGT,OAAO;EACL,GAAG;EACH,GAAI,sBACA;GACE;GACA,oBAAoB,kBAChB,aACA,SAAS;GACb,qBAAqB,yBACjB,aACA,SAAS;EACf,IACA;EACJ,GAAI,uBAAuB,EAAE,qBAAqB,KAAK,IAAI;CAC7D;AACF"}
1
+ {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\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 UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n editorOptions: EditorOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<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}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n editorOptions,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation>();\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (edit && instanceRef.current != null) {\n if (createEditor === undefined) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n const editor = createEditor(editorOptions ?? {});\n if (editor == null) {\n throw new Error(\n 'FileDiff: 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<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {\n ref,\n getHoveredLine,\n };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAqB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,eACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,QACmE;CACnE,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAA6B;CAClD,MAAM,cAAc,OAElB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QT,OAAO;EACL;EACA,gBARqB,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAIW;CACf;AACF;AASA,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,0BAGY;CAIZ,IAAI,EAFF,uBAAuB,0BAA0B,kBAGjD,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;AACF"}
@@ -20,17 +20,13 @@ function useFileInstance({ file, options, editorOptions, lineAnnotations, select
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
- edit,
24
23
  hasCustomHeader,
25
- hasEditor: createEditor !== void 0,
26
24
  hasGutterRenderUtility,
27
25
  options
28
26
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
29
27
  else instanceRef.current = new File(mergeFileOptions({
30
28
  controlledSelection,
31
- edit,
32
29
  hasCustomHeader,
33
- hasEditor: createEditor !== void 0,
34
30
  hasGutterRenderUtility,
35
31
  options
36
32
  }), !disableWorkerPool ? poolManager : void 0, true);
@@ -50,13 +46,11 @@ function useFileInstance({ file, options, editorOptions, lineAnnotations, select
50
46
  if (instanceRef.current == null) return;
51
47
  const newOptions = mergeFileOptions({
52
48
  controlledSelection,
53
- edit,
54
49
  hasCustomHeader,
55
- hasEditor: createEditor !== void 0,
56
50
  hasGutterRenderUtility,
57
51
  options
58
52
  });
59
- const forceRender = !areOptionsEqual(instanceRef.current.options, newOptions);
53
+ const forceRender = newOptions !== void 0 && !areOptionsEqual(instanceRef.current.options, newOptions);
60
54
  instanceRef.current.setOptions(newOptions);
61
55
  instanceRef.current.render({
62
56
  file,
@@ -85,22 +79,14 @@ function useFileInstance({ file, options, editorOptions, lineAnnotations, select
85
79
  }, [])
86
80
  };
87
81
  }
88
- function mergeFileOptions({ options, controlledSelection, edit, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
89
- const needsEditorOverrides = edit && hasEditor;
90
- const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
91
- if (!needsReactOverrides && !needsEditorOverrides) return options;
92
- let merged = { ...options };
93
- if (needsReactOverrides) merged = {
94
- ...merged,
82
+ function mergeFileOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
83
+ if (!(controlledSelection || hasGutterRenderUtility || hasCustomHeader)) return options;
84
+ return {
85
+ ...options,
95
86
  controlledSelection,
96
87
  renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
97
88
  renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
98
89
  };
99
- if (needsEditorOverrides) merged = {
100
- ...merged,
101
- useTokenTransformer: true
102
- };
103
- return merged;
104
90
  }
105
91
  //#endregion
106
92
  export { useFileInstance };
@@ -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 { 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;IACA,WAAW,iBAAiB,KAAA;IAC5B;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,gCAAgC;EAC9B,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA,WAAW,iBAAiB,KAAA;GAC5B;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,gCAAgC;EAC9B,IAAI,QAAQ,YAAY,WAAW,MAAM;GACvC,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MAAM,mCAAmC;GAErD,MAAM,SAAS,aAAa,iBAAiB,CAAC,CAAC;GAC/C,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,gEACF;GAEF,IAAI;IACF,OAAO,OAAO,KAAK,YAAY,OAAO;GACxC,SAAS,OAAO;IACd,OAAO,QAAQ;IACf,MAAM;GACR;EACF;CAEF,GAAG,CAAC,IAAI,CAAC;CAOT,OAAO;EAAE;EAAK,gBALS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CACuB;CAAE;AAC/B;AAWA,SAAS,iBAA8B,EACrC,SACA,qBACA,MACA,iBACA,WACA,0BAC2E;CAC3E,MAAM,uBAAuB,QAAQ;CACrC,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,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
+ {"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 hasCustomHeader,\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 hasCustomHeader,\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 hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instanceRef.current.options, newOptions);\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 hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\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;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;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,gCAAgC;EAC9B,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA;EACF,CAAC;EAID,MAAM,cACJ,eAAe,KAAA,KACf,CAAC,gBAAgB,YAAY,QAAQ,SAAS,UAAU;EAC1D,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,gCAAgC;EAC9B,IAAI,QAAQ,YAAY,WAAW,MAAM;GACvC,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MAAM,mCAAmC;GAErD,MAAM,SAAS,aAAa,iBAAiB,CAAC,CAAC;GAC/C,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,gEACF;GAEF,IAAI;IACF,OAAO,OAAO,KAAK,YAAY,OAAO;GACxC,SAAS,OAAO;IACd,OAAO,QAAQ;IACf,MAAM;GACR;EACF;CAEF,GAAG,CAAC,IAAI,CAAC;CAOT,OAAO;EAAE;EAAK,gBALS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CACuB;CAAE;AAC/B;AASA,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,0BAC2E;CAI3E,IAAI,EAFF,uBAAuB,0BAA0B,kBAGjD,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;AACF"}
@@ -66,7 +66,7 @@ function useUnresolvedFileInstance({ file, options, lineAnnotations, selectedLin
66
66
  onMergeConflictAction,
67
67
  options
68
68
  });
69
- const forceRender = !areOptionsEqual(instance.options, newOptions);
69
+ const forceRender = newOptions !== void 0 && !areOptionsEqual(instance.options, newOptions);
70
70
  instance.setOptions(newOptions);
71
71
  instance.render({
72
72
  fileDiff,
@@ -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 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,YAA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U;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"}
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 // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !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,W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kBAAkB,aAAa,KAAA;EACnD,qBAAqB,yBAAyB,aAAa,KAAA;CAC7D;AACF"}
@@ -87,12 +87,18 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
87
87
  recycle(): void;
88
88
  /**
89
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.
90
+ * skeleton instead of recomputing hunks, and rendering happens locally
91
+ * with the token transformer forced on (worker-pool requests/results are
92
+ * suspended for this renderer). Called on every editor attach, including
93
+ * a re-attach after recycle.
92
94
  */
93
95
  beginEditSession(): void;
94
96
  /** Leave edit-session mode. The exit recompute is the host's concern. */
95
97
  endEditSession(): void;
98
+ /**
99
+ * Ensures that the DOM is compatible with editor render updates
100
+ */
101
+ editorRenderReady(): boolean;
96
102
  /**
97
103
  * Re-highlights the current diff in the background and swaps the fresh
98
104
  * result in (with a re-render) once it completes. Needed after an edit
@@ -139,6 +145,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
139
145
  protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;
140
146
  initializeHighlighter(): Promise<DiffsHighlighter>;
141
147
  hydrate(diff: FileDiffMetadata | undefined): void;
148
+ private getLocalHighlightTheme;
142
149
  private getRenderOptions;
143
150
  renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;
144
151
  asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;
@@ -146,6 +153,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
146
153
  private asyncHighlight;
147
154
  private renderDiffWithHighlighter;
148
155
  onHighlightSuccess(diff: FileDiffMetadata, result: ThemedDiffResult, options: RenderDiffOptions, highlighted?: boolean): void;
156
+ private applyHighlightResult;
149
157
  private getMatchingWorkerResultCache;
150
158
  private hasHighlightedRenderCache;
151
159
  onHighlightError(error: unknown): void;
@@ -1 +1 @@
1
- {"version":3,"file":"DiffHunksRenderer.d.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BAAA;EAsCD,UAAA,CACL,IAAA,GAAM,gBAAA,cACN,WAAA,GAAa,WAAA,GACZ,iBAAA;EAuJU,WAAA,CACX,IAAA,EAAM,gBAAA,EACN,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,QAQM,oBAAA;EAAA,QA+BA,4BAAA;EAAA,QAcA,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"}
@@ -17,7 +17,6 @@ import { createPreElement } from "../utils/createPreElement.js";
17
17
  import { getFiletypeFromFileName } from "../utils/getFiletypeFromFileName.js";
18
18
  import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
19
19
  import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
20
- import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
21
20
  import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
22
21
  import { iterateOverDiff } from "../utils/iterateOverDiff.js";
23
22
  import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
@@ -68,8 +67,10 @@ var DiffHunksRenderer = class {
68
67
  }
69
68
  /**
70
69
  * 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.
70
+ * skeleton instead of recomputing hunks, and rendering happens locally
71
+ * with the token transformer forced on (worker-pool requests/results are
72
+ * suspended for this renderer). Called on every editor attach, including
73
+ * a re-attach after recycle.
73
74
  */
74
75
  beginEditSession() {
75
76
  this.editSessionActive = true;
@@ -79,6 +80,12 @@ var DiffHunksRenderer = class {
79
80
  this.editSessionActive = false;
80
81
  }
81
82
  /**
83
+ * Ensures that the DOM is compatible with editor render updates
84
+ */
85
+ editorRenderReady() {
86
+ return this.renderCache?.options.useTokenTransformer === true && this.renderCache.highlighted && this.renderCache.result != null;
87
+ }
88
+ /**
82
89
  * Re-highlights the current diff in the background and swaps the fresh
83
90
  * result in (with a re-render) once it completes. Needed after an edit
84
91
  * session's exit recompute: session passes plain-fill shifted lines in the
@@ -93,7 +100,7 @@ var DiffHunksRenderer = class {
93
100
  if (renderCache == null || isDiffPlainText(renderCache.diff) || isDiffMassive(renderCache.diff, this.getTokenizeMaxLength())) return Promise.resolve();
94
101
  const { diff } = renderCache;
95
102
  const { workerManager } = this;
96
- if (workerManager?.isWorkingPool() === true && diff.cacheKey != null) {
103
+ if (!this.editSessionActive && workerManager?.isWorkingPool() === true && diff.cacheKey != null) {
97
104
  workerManager.evictDiffFromCache(diff.cacheKey);
98
105
  return workerManager.primeDiffHighlightCache(diff).then(() => {
99
106
  this.applyRefreshedResult(diff, workerManager.getDiffResultCache(diff));
@@ -325,7 +332,10 @@ var DiffHunksRenderer = class {
325
332
  };
326
333
  }
327
334
  async initializeHighlighter() {
328
- this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, this.options));
335
+ this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, {
336
+ theme: this.getLocalHighlightTheme(),
337
+ preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
338
+ }));
329
339
  return this.highlighter;
330
340
  }
331
341
  hydrate(diff) {
@@ -342,20 +352,30 @@ var DiffHunksRenderer = class {
342
352
  result: massiveDiff ? void 0 : cache?.result,
343
353
  renderRange: void 0
344
354
  };
345
- if (this.workerManager?.isWorkingPool() === true) {
355
+ if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
346
356
  if (this.renderCache.result == null && !massiveDiff) this.workerManager.highlightDiffAST(this, this.diff);
347
357
  } else if (this.highlighter == null) {
348
358
  this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);
349
359
  this.initializeHighlighter();
350
360
  }
351
361
  }
362
+ getLocalHighlightTheme() {
363
+ return this.workerManager?.getDiffRenderOptions().theme ?? this.options.theme ?? DEFAULT_THEMES;
364
+ }
352
365
  getRenderOptions(diff) {
353
366
  const options = (() => {
354
- if (this.workerManager?.isWorkingPool() === true) return this.workerManager.getDiffRenderOptions();
367
+ if (this.workerManager?.isWorkingPool() === true) {
368
+ const poolOptions = this.workerManager.getDiffRenderOptions();
369
+ if (this.editSessionActive && poolOptions.useTokenTransformer !== true) return {
370
+ ...poolOptions,
371
+ useTokenTransformer: true
372
+ };
373
+ return poolOptions;
374
+ }
355
375
  const { theme, tokenizeMaxLineLength, lineDiffType, maxLineDiffLength } = this.getOptionsWithDefaults();
356
376
  return {
357
377
  theme,
358
- useTokenTransformer: shouldUseTokenTransformer(this.options),
378
+ useTokenTransformer: this.editSessionActive || this.options.useTokenTransformer === true,
359
379
  tokenizeMaxLineLength,
360
380
  lineDiffType,
361
381
  maxLineDiffLength
@@ -401,7 +421,7 @@ var DiffHunksRenderer = class {
401
421
  const forcePlainText = !hasContent || isDiffPlainText(diff) || isDiffMassive(diff, this.getTokenizeMaxLength());
402
422
  const newContent = !areDiffTargetsEqual(diff, this.renderCache.diff);
403
423
  const newRenderRange = !areRenderRangesEqual(this.renderCache.renderRange, renderRange);
404
- if (this.workerManager?.isWorkingPool() === true) {
424
+ if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
405
425
  const highlightPending = this.renderCache.result == null && this.renderCache.highlighted && !forcePlainText && !newContent && isDefaultRenderRange(renderRange);
406
426
  if (highlightPending) this.renderCache.highlightPending = true;
407
427
  if (!highlightPending && (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (newContent || newRenderRange))) {
@@ -429,7 +449,7 @@ var DiffHunksRenderer = class {
429
449
  }
430
450
  if (!hasThemes || !forcePlainText && !hasLangs) this.asyncHighlight(diff).then(({ result, options }) => {
431
451
  if (this.renderCache != null) this.renderCache.highlighted = false;
432
- this.onHighlightSuccess(diff, result, options, !forcePlainText);
452
+ this.applyHighlightResult(diff, result, options, !forcePlainText);
433
453
  });
434
454
  }
435
455
  return this.renderCache.result != null ? this.processDiffResult(this.renderCache.diff, renderRange, this.renderCache.result) : void 0;
@@ -454,7 +474,7 @@ var DiffHunksRenderer = class {
454
474
  async asyncHighlight(diff) {
455
475
  const forcePlainText = isDiffMassive(diff, this.getTokenizeMaxLength());
456
476
  this.computedLang = forcePlainText ? "text" : diff.lang ?? getFiletypeFromFileName(diff.name);
457
- const hasThemes = this.highlighter != null && areThemesAttached(this.options.theme ?? DEFAULT_THEMES);
477
+ const hasThemes = this.highlighter != null && areThemesAttached(this.getLocalHighlightTheme());
458
478
  const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLang);
459
479
  if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
460
480
  return this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText);
@@ -472,6 +492,10 @@ var DiffHunksRenderer = class {
472
492
  };
473
493
  }
474
494
  onHighlightSuccess(diff, result, options, highlighted = true) {
495
+ if (this.editSessionActive) return;
496
+ this.applyHighlightResult(diff, result, options, highlighted);
497
+ }
498
+ applyHighlightResult(diff, result, options, highlighted = true) {
475
499
  if (this.renderCache == null) return;
476
500
  const triggerRenderUpdate = this.renderCache.highlightPending === true || !this.renderCache.highlighted || !areDiffRenderOptionsEqual(this.renderCache.options, options) || !areDiffTargetsEqual(this.renderCache.diff, diff);
477
501
  this.renderCache = {
@@ -484,6 +508,7 @@ var DiffHunksRenderer = class {
484
508
  if (triggerRenderUpdate) this.onRenderUpdate?.();
485
509
  }
486
510
  getMatchingWorkerResultCache(diff, options) {
511
+ if (this.editSessionActive) return;
487
512
  const cache = this.workerManager?.getDiffResultCache(diff);
488
513
  if (cache == null || !areDiffRenderOptionsEqual(options, cache.options)) return;
489
514
  return cache;