@pierre/diffs 1.3.0-beta.6 → 1.3.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +4 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +45 -6
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +5 -2
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +36 -23
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +126 -58
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +3 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +4 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +3 -7
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +10 -4
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +178 -49
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/editor/editor.d.ts +2 -2
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +163 -106
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/selection.d.ts +1 -1
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +87 -37
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +25 -7
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenzier.d.ts +2 -0
- package/dist/editor/tokenzier.d.ts.map +1 -1
- package/dist/editor/tokenzier.js +11 -3
- package/dist/editor/tokenzier.js.map +1 -1
- package/dist/editor/utils.d.ts +3 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +14 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +0 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/react/EditorContext.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +3 -4
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/utils/useFileDiffInstance.js +14 -15
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +29 -16
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +11 -10
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +14 -6
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/types.d.ts +59 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/areHunkDataEqual.js +1 -1
- package/dist/utils/areHunkDataEqual.js.map +1 -1
- package/dist/utils/awaitWithTimeout.d.ts +5 -0
- package/dist/utils/awaitWithTimeout.d.ts.map +1 -0
- package/dist/utils/awaitWithTimeout.js +15 -0
- package/dist/utils/awaitWithTimeout.js.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts +7 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.js +16 -0
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -0
- package/dist/utils/computeEstimatedDiffHeights.d.ts +3 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +8 -1
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/createPreElement.js +0 -1
- package/dist/utils/createPreElement.js.map +1 -1
- package/dist/utils/getDiffFileInput.d.ts +14 -0
- package/dist/utils/getDiffFileInput.d.ts.map +1 -0
- package/dist/utils/getDiffFileInput.js +24 -0
- package/dist/utils/getDiffFileInput.js.map +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js +2 -0
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts +10 -0
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -0
- package/dist/utils/hydratePartialDiff.js +140 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -0
- package/dist/utils/iterateOverDiff.js +3 -3
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +1 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +26 -5
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +0 -1
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +5 -1
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +26 -4
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +7 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +78 -15
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/index.d.ts +2 -2
- package/dist/worker/types.d.ts +7 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +5 -3
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +5 -3
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -83,22 +83,21 @@ function mergeFileDiffOptions({ options, controlledSelection, contentEditable, h
|
|
|
83
83
|
const needsEditorOptions = contentEditable && hasEditor;
|
|
84
84
|
const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
|
|
85
85
|
if (!needsReactOverrides && !needsEditorOptions) return options;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
...
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
return {
|
|
87
|
+
...options,
|
|
88
|
+
...needsReactOverrides ? {
|
|
89
|
+
controlledSelection,
|
|
90
|
+
renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
|
|
91
|
+
renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
|
|
92
|
+
} : null,
|
|
93
|
+
...needsEditorOptions ? {
|
|
94
|
+
useTokenTransformer: true,
|
|
95
|
+
enableGutterUtility: false,
|
|
96
|
+
enableLineSelection: false,
|
|
97
|
+
expandUnchanged: true,
|
|
98
|
+
lineHoverHighlight: "disabled"
|
|
99
|
+
} : null
|
|
100
100
|
};
|
|
101
|
-
return merged;
|
|
102
101
|
}
|
|
103
102
|
//#endregion
|
|
104
103
|
export { useFileDiffInstance };
|
|
@@ -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 { 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 { 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 UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<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 contentEditable: 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 lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<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 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 FileDiff(\n mergeFileDiffOptions({\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 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 useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== 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 useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('FileDiff: 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<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {
|
|
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 { 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 { 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 UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<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 contentEditable: 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 lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<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 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 FileDiff(\n mergeFileDiffOptions({\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 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 useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== 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 useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('FileDiff: 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<'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 contentEditable: 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 contentEditable,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsEditorOptions = contentEditable && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOptions) {\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 ...(needsEditorOptions\n ? {\n useTokenTransformer: true,\n enableGutterUtility: false,\n enableLineSelection: false,\n expandUnchanged: true,\n lineHoverHighlight: 'disabled',\n }\n : null),\n };\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAoB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,mBACmE;CACnE,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,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,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GAC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AoB;EACtB,IACA;CACN;AACF"}
|
|
@@ -84,7 +84,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
84
84
|
constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);
|
|
85
85
|
cleanUp(): void;
|
|
86
86
|
recycle(): void;
|
|
87
|
-
|
|
87
|
+
getDiffCache(): FileDiffMetadata | undefined;
|
|
88
88
|
clearRenderCache(): void;
|
|
89
89
|
setOptions(options: DiffHunksRendererOptions): void;
|
|
90
90
|
mergeOptions(options: Partial<DiffHunksRendererOptions>): void;
|
|
@@ -92,7 +92,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
92
92
|
getExpandedHunk(hunkIndex: number): HunkExpansionRegion;
|
|
93
93
|
getExpandedHunksMap(): Map<number, HunkExpansionRegion>;
|
|
94
94
|
setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;
|
|
95
|
-
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light'
|
|
95
|
+
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light'): void;
|
|
96
96
|
applyDocumentChange(textDocument: DiffsTextDocument): void;
|
|
97
97
|
protected getUnifiedLineDecoration({
|
|
98
98
|
lineType
|
|
@@ -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,S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,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,QA0BM,4BAAA;EAAA,QAWA,yBAAA;EAaD,gBAAA,CAAiB,KAAA;EAAA,QAIhB,oBAAA;EAAA,QAIA,iBAAA;EA6iBD,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"}
|
|
@@ -15,6 +15,7 @@ import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
|
15
15
|
import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
|
|
16
16
|
import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
|
|
17
17
|
import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
|
|
18
|
+
import { splitFileContents } from "../utils/splitFileContents.js";
|
|
18
19
|
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
19
20
|
import { cleanLastNewline } from "../utils/cleanLastNewline.js";
|
|
20
21
|
import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
|
|
@@ -26,8 +27,7 @@ import { getTotalLineCountFromHunks } from "../utils/getTotalLineCountFromHunks.
|
|
|
26
27
|
import { isDefaultRenderRange } from "../utils/isDefaultRenderRange.js";
|
|
27
28
|
import { isDiffPlainText } from "../utils/isDiffPlainText.js";
|
|
28
29
|
import { renderDiffWithHighlighter } from "../utils/renderDiffWithHighlighter.js";
|
|
29
|
-
import {
|
|
30
|
-
import { recomputeDiffHunks, recomputeEmptyDocumentDiff, updateDiffHunks } from "../utils/updateDiffHunks.js";
|
|
30
|
+
import { recomputeDiffHunksForEdit, recomputeEmptyDocumentDiff, updateDiffHunks } from "../utils/updateDiffHunks.js";
|
|
31
31
|
import { toHtml } from "hast-util-to-html";
|
|
32
32
|
//#region src/renderers/DiffHunksRenderer.ts
|
|
33
33
|
let instanceId = -1;
|
|
@@ -63,7 +63,7 @@ var DiffHunksRenderer = class {
|
|
|
63
63
|
this.deletionAnnotations = {};
|
|
64
64
|
this.workerManager?.cleanUpTasks(this);
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
getDiffCache() {
|
|
67
67
|
return this.renderCache?.diff ?? this.diff;
|
|
68
68
|
}
|
|
69
69
|
clearRenderCache() {
|
|
@@ -111,7 +111,7 @@ var DiffHunksRenderer = class {
|
|
|
111
111
|
arr.push(annotation);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
updateRenderCache(dirtyLines, themeType
|
|
114
|
+
updateRenderCache(dirtyLines, themeType) {
|
|
115
115
|
if (this.renderCache == null) return;
|
|
116
116
|
const { result, diff } = this.renderCache;
|
|
117
117
|
if (result == null) return;
|
|
@@ -164,7 +164,7 @@ var DiffHunksRenderer = class {
|
|
|
164
164
|
})
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
|
-
if (
|
|
167
|
+
if (changedAdditionLines.length > 0) Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
168
168
|
result.baseThemeType = themeType;
|
|
169
169
|
this.renderCache.isDirty = true;
|
|
170
170
|
}
|
|
@@ -172,16 +172,21 @@ var DiffHunksRenderer = class {
|
|
|
172
172
|
if (this.renderCache == null) return;
|
|
173
173
|
const { diff, result } = this.renderCache;
|
|
174
174
|
if (result == null) return;
|
|
175
|
-
|
|
175
|
+
const documentText = textDocument.getText();
|
|
176
|
+
if (documentText.trim().length === 0) {
|
|
177
|
+
const lines = [];
|
|
178
|
+
for (let line = 0; line < textDocument.lineCount; line++) lines.push(textDocument.getLineText(line, true));
|
|
179
|
+
diff.additionLines = lines;
|
|
180
|
+
} else diff.additionLines = splitFileContents(documentText);
|
|
176
181
|
const newLength = diff.additionLines.length;
|
|
177
182
|
const additionHastLines = result.code.additionLines;
|
|
178
183
|
const prevLen = additionHastLines.length;
|
|
179
184
|
if (newLength < prevLen) additionHastLines.length = newLength;
|
|
180
185
|
for (let i = prevLen; i < newLength; i++) additionHastLines[i] ??= createPlainAdditionLineElement(i, textDocument);
|
|
181
|
-
if (!diff.isPartial) if (
|
|
186
|
+
if (!diff.isPartial) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
182
187
|
Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
183
188
|
additionHastLines[0] = createPlainAdditionLineElement(0, textDocument);
|
|
184
|
-
} else Object.assign(diff,
|
|
189
|
+
} else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
|
|
185
190
|
this.renderCache.isDirty = true;
|
|
186
191
|
}
|
|
187
192
|
getUnifiedLineDecoration({ lineType }) {
|
|
@@ -403,6 +408,8 @@ var DiffHunksRenderer = class {
|
|
|
403
408
|
const isRenderCacheDirty = this.renderCache?.isDirty ?? false;
|
|
404
409
|
this.diff = fileDiff;
|
|
405
410
|
const unified = diffStyle === "unified";
|
|
411
|
+
const canHydrateContext = canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null);
|
|
412
|
+
const isExpandableDiff = !fileDiff.isPartial || canHydrateContext;
|
|
406
413
|
let additionsContentAST = [];
|
|
407
414
|
let deletionsContentAST = [];
|
|
408
415
|
let unifiedContentAST = [];
|
|
@@ -494,7 +501,7 @@ var DiffHunksRenderer = class {
|
|
|
494
501
|
hunkSpecs: hunk?.hunkSpecs,
|
|
495
502
|
isFirstHunk: hunkIndex === 0,
|
|
496
503
|
isLastHunk: false,
|
|
497
|
-
isExpandable:
|
|
504
|
+
isExpandable: isExpandableDiff
|
|
498
505
|
});
|
|
499
506
|
const lineIndex = diffStyle === "unified" ? unifiedLineIndex : splitLineIndex;
|
|
500
507
|
const renderedLineContext = {
|
|
@@ -603,6 +610,7 @@ var DiffHunksRenderer = class {
|
|
|
603
610
|
if (injectedRows?.after != null) pushSplitInjectedRows(injectedRows.after, context, pendingSplitContext);
|
|
604
611
|
}
|
|
605
612
|
const isFinalSplitHunkRow = diffStyle === "split" && hunk != null && splitLineIndex === hunk.splitLineStart + hunk.splitLineCount - 1;
|
|
613
|
+
const isFinalHunkRow = hunkIndex === fileDiff.hunks.length - 1 && hunk != null && (diffStyle === "split" ? splitLineIndex === hunk.splitLineStart + hunk.splitLineCount - 1 : unifiedLineIndex === hunk.unifiedLineStart + hunk.unifiedLineCount - 1);
|
|
606
614
|
const splitNoEOFCRDeletion = isFinalSplitHunkRow ? hunk.noEOFCRDeletions : false;
|
|
607
615
|
const splitNoEOFCRAddition = isFinalSplitHunkRow ? hunk.noEOFCRAdditions : false;
|
|
608
616
|
const noEOFCRDeletion = (deletionLine?.noEOFCR ?? false) || splitNoEOFCRDeletion;
|
|
@@ -639,14 +647,14 @@ var DiffHunksRenderer = class {
|
|
|
639
647
|
}
|
|
640
648
|
context.incrementRowCount(1);
|
|
641
649
|
}
|
|
642
|
-
if (
|
|
650
|
+
if (hunkSeparators !== "simple" && hunkSeparators !== "metadata" && (collapsedAfter > 0 || isFinalHunkRow && canHydrateContext)) pushSeparators({
|
|
643
651
|
hunkIndex: type === "context-expanded" ? hunkIndex : hunkIndex + 1,
|
|
644
|
-
collapsedLines: collapsedAfter,
|
|
652
|
+
collapsedLines: isFinalHunkRow && canHydrateContext ? "unknown" : collapsedAfter,
|
|
645
653
|
rangeSize: trailingRangeSize,
|
|
646
654
|
hunkSpecs: void 0,
|
|
647
655
|
isFirstHunk: false,
|
|
648
656
|
isLastHunk: true,
|
|
649
|
-
isExpandable:
|
|
657
|
+
isExpandable: isExpandableDiff
|
|
650
658
|
});
|
|
651
659
|
context.incrementRowCount(1);
|
|
652
660
|
}
|
|
@@ -886,7 +894,7 @@ function pushLineWithAnnotation({ diffStyle, type, deletionLine, additionLine, u
|
|
|
886
894
|
if (hasAnnotationRow) context.incrementRowCount(1);
|
|
887
895
|
}
|
|
888
896
|
function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs, isFirstHunk, isLastHunk, isExpandable }, context) {
|
|
889
|
-
if (collapsedLines <= 0) return;
|
|
897
|
+
if (typeof collapsedLines === "number" && collapsedLines <= 0) return;
|
|
890
898
|
const linesAST = type === "unified" ? context.unifiedContentAST : type === "deletions" ? context.deletionsContentAST : context.additionsContentAST;
|
|
891
899
|
if (context.hunkSeparators === "metadata") {
|
|
892
900
|
if (hunkSpecs != null) {
|
|
@@ -925,9 +933,10 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
925
933
|
const slotName = getHunkSeparatorSlotName(type, hunkIndex);
|
|
926
934
|
const chunked = rangeSize > context.expansionLineCount;
|
|
927
935
|
const expandIndex = isExpandable ? hunkIndex : void 0;
|
|
936
|
+
const content = typeof collapsedLines === "number" ? getModifiedLinesString(collapsedLines) : "More unchanged context may be available";
|
|
928
937
|
context.pushToGutter(type, createSeparator({
|
|
929
938
|
type: context.hunkSeparators,
|
|
930
|
-
content
|
|
939
|
+
content,
|
|
931
940
|
expandIndex,
|
|
932
941
|
chunked,
|
|
933
942
|
slotName,
|
|
@@ -936,7 +945,7 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
936
945
|
}));
|
|
937
946
|
linesAST.push(createSeparator({
|
|
938
947
|
type: context.hunkSeparators,
|
|
939
|
-
content
|
|
948
|
+
content,
|
|
940
949
|
expandIndex,
|
|
941
950
|
chunked,
|
|
942
951
|
slotName,
|
|
@@ -947,7 +956,8 @@ function pushSeparator(type, { hunkIndex, collapsedLines, rangeSize, hunkSpecs,
|
|
|
947
956
|
context.hunkData.push({
|
|
948
957
|
slotName,
|
|
949
958
|
hunkIndex,
|
|
950
|
-
lines: collapsedLines,
|
|
959
|
+
lines: typeof collapsedLines === "number" ? collapsedLines : 0,
|
|
960
|
+
lineCountKnown: typeof collapsedLines === "number",
|
|
951
961
|
type,
|
|
952
962
|
expandable: isExpandable ? {
|
|
953
963
|
up: !isFirstHunk,
|
|
@@ -996,6 +1006,9 @@ function applyLineTextWithNewline(line, lineText) {
|
|
|
996
1006
|
function isDiffMassive(diff, tokenizeMaxLength) {
|
|
997
1007
|
return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
|
|
998
1008
|
}
|
|
1009
|
+
function canHydrateCollapsedContext(fileDiff, hasFileLoader) {
|
|
1010
|
+
return fileDiff.isPartial && hasFileLoader && (fileDiff.type === "change" || fileDiff.type === "rename-changed");
|
|
1011
|
+
}
|
|
999
1012
|
//#endregion
|
|
1000
1013
|
export { DiffHunksRenderer };
|
|
1001
1014
|
|