@pierre/diffs 1.3.5 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +113 -68
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +153 -58
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +75 -15
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +223 -62
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +97 -21
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +400 -100
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +2 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +16 -7
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +140 -51
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +14 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +183 -93
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/edit/index.d.ts +7 -4
- package/dist/edit/index.js +5 -1
- package/dist/editor/EditStateManager.d.ts +56 -0
- package/dist/editor/EditStateManager.d.ts.map +1 -0
- package/dist/editor/EditStateManager.js +135 -0
- package/dist/editor/EditStateManager.js.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +7 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js +16 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js.map +1 -0
- package/dist/editor/editPrediction.d.ts +76 -0
- package/dist/editor/editPrediction.d.ts.map +1 -0
- package/dist/editor/editPrediction.js +365 -0
- package/dist/editor/editPrediction.js.map +1 -0
- package/dist/editor/editStack.d.ts +19 -40
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js +67 -4
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +118 -29
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +1196 -403
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/languages.d.ts +3 -3
- package/dist/editor/languages.d.ts.map +1 -1
- package/dist/editor/languages.js.map +1 -1
- package/dist/editor/lineAnnotations.d.ts +3 -3
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +16 -7
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +2 -2
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +2 -2
- package/dist/editor/matchBrackets.d.ts.map +1 -1
- package/dist/editor/matchBrackets.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +2 -2
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +3 -2
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +33 -23
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +3 -3
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +3 -3
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/textDocument.d.ts +11 -8
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +28 -5
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textDocumentChangeTransaction.d.ts +15 -0
- package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -0
- package/dist/editor/textDocumentChangeTransaction.js +12 -0
- package/dist/editor/textDocumentChangeTransaction.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +5 -0
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +10 -0
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +1 -1
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +6 -3
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/editor/types.d.ts +267 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/editor/types.js +0 -0
- package/dist/editor/utils.d.ts +2 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +4 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +9 -8
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +7 -0
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +36 -25
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +15 -14
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +8 -11
- package/dist/react/EditContext.d.ts.map +1 -1
- package/dist/react/EditContext.js +2 -9
- package/dist/react/EditContext.js.map +1 -1
- package/dist/react/File.d.ts +10 -6
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +8 -4
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +10 -5
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +8 -4
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +8 -5
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +8 -12
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +7 -4
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +8 -4
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +3 -3
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +8 -5
- package/dist/react/types.d.ts +46 -9
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +14 -12
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +2 -2
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +14 -12
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +2 -2
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +22 -10
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +112 -22
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +15 -9
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +84 -25
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +30 -15
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +172 -108
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +27 -11
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +138 -64
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
- package/dist/shiki-stream/tokenizer.js +2 -1
- package/dist/shiki-stream/tokenizer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +21 -21
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +1 -1
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.d.ts +6 -6
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/ssr/preloadPatchFile.d.ts +4 -4
- package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +13 -263
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/appendItems.d.ts +5 -0
- package/dist/utils/appendItems.d.ts.map +1 -0
- package/dist/utils/appendItems.js +8 -0
- package/dist/utils/appendItems.js.map +1 -0
- package/dist/utils/areDiffTargetsEqual.js +1 -1
- package/dist/utils/areDiffTargetsEqual.js.map +1 -1
- package/dist/utils/areFileTargetsEqual.d.ts +7 -0
- package/dist/utils/areFileTargetsEqual.d.ts.map +1 -0
- package/dist/utils/areFileTargetsEqual.js +8 -0
- package/dist/utils/areFileTargetsEqual.js.map +1 -0
- package/dist/utils/areManagedSnapshotsEqual.d.ts +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/areOptionsEqual.d.ts +3 -3
- package/dist/utils/areOptionsEqual.d.ts.map +1 -1
- package/dist/utils/areOptionsEqual.js.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +3 -2
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.js +8 -5
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -1
- package/dist/utils/composeCacheKey.d.ts +6 -0
- package/dist/utils/composeCacheKey.d.ts.map +1 -0
- package/dist/utils/composeCacheKey.js +10 -0
- package/dist/utils/composeCacheKey.js.map +1 -0
- package/dist/utils/editSessionAnnotations.d.ts +69 -0
- package/dist/utils/editSessionAnnotations.d.ts.map +1 -0
- package/dist/utils/editSessionAnnotations.js +64 -0
- package/dist/utils/editSessionAnnotations.js.map +1 -0
- package/dist/utils/editSessionHunks.d.ts +5 -3
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.js +7 -5
- package/dist/utils/editSessionHunks.js.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts +1 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
- package/dist/utils/hydratePartialDiff.js +2 -1
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/lineAnnotationIdentity.d.ts +16 -0
- package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -0
- package/dist/utils/lineAnnotationIdentity.js +17 -0
- package/dist/utils/lineAnnotationIdentity.js.map +1 -0
- package/dist/utils/parseDiffFromFile.d.ts +2 -2
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +6 -6
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +6 -3
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +34 -9
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +6 -5
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +7 -4
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/trimPatchContext.d.ts.map +1 -1
- package/dist/utils/trimPatchContext.js +3 -2
- package/dist/utils/trimPatchContext.js.map +1 -1
- package/dist/utils/updateDiffHunks.js +1 -1
- package/dist/utils/virtualDiffLayout.js +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +4 -3
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +33 -4
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/types.d.ts +5 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +14 -6
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +14 -6
- package/dist/worker/worker.js.map +1 -1
- package/package.json +9 -1
- package/dist/editor/stateStorage.d.ts +0 -15
- package/dist/editor/stateStorage.d.ts.map +0 -1
- package/dist/editor/stateStorage.js +0 -65
- package/dist/editor/stateStorage.js.map +0 -1
|
@@ -7,7 +7,6 @@ import { areOptionsEqual } from "../utils/areOptionsEqual.js";
|
|
|
7
7
|
import { areSelectionsEqual } from "../utils/areSelectionsEqual.js";
|
|
8
8
|
import { createCodeViewHeaderFooterHostElement } from "../utils/createCodeViewHeaderFooterHostElement.js";
|
|
9
9
|
import { createWindowFromScrollPosition } from "../utils/createWindowFromScrollPosition.js";
|
|
10
|
-
import { finishEditSessionForDiff } from "../utils/editSessionHunks.js";
|
|
11
10
|
import { isStyleNode } from "../utils/isStyleNode.js";
|
|
12
11
|
import { prefersReducedMotion } from "../utils/prefersReducedMotion.js";
|
|
13
12
|
import { roundToDevicePixel } from "../utils/roundToDevicePixel.js";
|
|
@@ -402,13 +401,31 @@ var CodeView = class CodeView {
|
|
|
402
401
|
this.clearReadySubscription();
|
|
403
402
|
this.restoreScrollInteractions();
|
|
404
403
|
this.cleanAllRenderedItems();
|
|
405
|
-
|
|
404
|
+
const teardownSessions = [...this.itemEditors.values()].map((record) => {
|
|
405
|
+
const item = this.idToItem.get(record.state.id);
|
|
406
|
+
if (item != null) record.state.removedItem = item.item;
|
|
407
|
+
return {
|
|
408
|
+
record,
|
|
409
|
+
instance: item?.instance
|
|
410
|
+
};
|
|
411
|
+
});
|
|
406
412
|
this.itemEditors.clear();
|
|
407
413
|
this.attachedEditors.clear();
|
|
408
414
|
this.selectedLines = null;
|
|
409
415
|
this.items.length = 0;
|
|
410
416
|
this.idToItem.clear();
|
|
411
417
|
this.instanceToItem.clear();
|
|
418
|
+
let failed = false;
|
|
419
|
+
let failure;
|
|
420
|
+
for (const { record, instance } of teardownSessions) try {
|
|
421
|
+
record.editor.cleanUp("discard");
|
|
422
|
+
instance?.cleanUp();
|
|
423
|
+
} catch (error) {
|
|
424
|
+
if (!failed) {
|
|
425
|
+
failed = true;
|
|
426
|
+
failure = error;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
412
429
|
this.layoutDirtyIndex = void 0;
|
|
413
430
|
this.pendingLayoutReset = void 0;
|
|
414
431
|
this.stickyContainer.textContent = "";
|
|
@@ -429,9 +446,17 @@ var CodeView = class CodeView {
|
|
|
429
446
|
this.heightDirty = true;
|
|
430
447
|
this.resetRenderState();
|
|
431
448
|
if (!this.isContainerManaged) this.flushSlotCoordinator();
|
|
449
|
+
if (failed) throw failure;
|
|
432
450
|
}
|
|
433
451
|
cleanUp() {
|
|
434
|
-
|
|
452
|
+
let resetFailed = false;
|
|
453
|
+
let resetFailure;
|
|
454
|
+
try {
|
|
455
|
+
this.reset();
|
|
456
|
+
} catch (error) {
|
|
457
|
+
resetFailed = true;
|
|
458
|
+
resetFailure = error;
|
|
459
|
+
}
|
|
435
460
|
this.clearElementPool();
|
|
436
461
|
this.restoreScrollInteractions();
|
|
437
462
|
this.workerManager?.unsubscribeToThemeChanges(this);
|
|
@@ -457,6 +482,7 @@ var CodeView = class CodeView {
|
|
|
457
482
|
this.footer.height = 0;
|
|
458
483
|
this.root = void 0;
|
|
459
484
|
this.container = void 0;
|
|
485
|
+
if (resetFailed) throw resetFailure;
|
|
460
486
|
}
|
|
461
487
|
cleanAllRenderedItems() {
|
|
462
488
|
if (this.renderState.firstIndex === -1) return;
|
|
@@ -585,7 +611,8 @@ var CodeView = class CodeView {
|
|
|
585
611
|
/**
|
|
586
612
|
* Get the live editor for an item currently in edit mode. Use this to drive
|
|
587
613
|
* editor APIs CodeView does not wrap (applyEdits, undo, setMarkers, …).
|
|
588
|
-
* Returns undefined once the item
|
|
614
|
+
* Returns undefined once the item's session ends (edit off or removal); a
|
|
615
|
+
* collapsed item keeps its suspended editor.
|
|
589
616
|
*/
|
|
590
617
|
getEditor(itemId) {
|
|
591
618
|
return this.itemEditors.get(itemId)?.editor;
|
|
@@ -628,7 +655,6 @@ var CodeView = class CodeView {
|
|
|
628
655
|
}
|
|
629
656
|
const editorRecord = this.itemEditors.get(oldId);
|
|
630
657
|
if (editorRecord != null) {
|
|
631
|
-
editorRecord.state.id = newId;
|
|
632
658
|
this.itemEditors.delete(oldId);
|
|
633
659
|
this.itemEditors.set(newId, editorRecord);
|
|
634
660
|
if (this.attachedEditors.delete(oldId)) this.attachedEditors.add(newId);
|
|
@@ -888,58 +914,63 @@ var CodeView = class CodeView {
|
|
|
888
914
|
return item.item.edit === true && item.item.collapsed !== true;
|
|
889
915
|
}
|
|
890
916
|
/**
|
|
891
|
-
*
|
|
917
|
+
* Lazily create and attach the editor for a mounted edit-mode item. Called
|
|
892
918
|
* from the render loop so every mounted item passes through it: fresh
|
|
893
919
|
* mounts, remounts after virtualization released the item, and items whose
|
|
894
920
|
* edit flag was just turned on. Editors persist across unmounts, so a
|
|
895
|
-
* remounted item
|
|
896
|
-
*
|
|
897
|
-
*
|
|
921
|
+
* remounted item resumes its existing editor and retained document; the
|
|
922
|
+
* instance retains its private session model so the remount
|
|
923
|
+
* paints the edited text without changing the host input.
|
|
898
924
|
*/
|
|
899
925
|
attachItemEditor(item) {
|
|
900
926
|
const { id } = item.item;
|
|
901
927
|
const { createEditor } = this.options;
|
|
902
928
|
if (item.element == null || this.attachedEditors.has(id) || !this.isItemInEditMode(item)) return;
|
|
903
|
-
|
|
904
|
-
let createdEditor
|
|
929
|
+
const record = this.itemEditors.get(id);
|
|
930
|
+
let createdEditor;
|
|
905
931
|
try {
|
|
906
932
|
if (record == null) {
|
|
907
933
|
assertEditorFactory(createEditor);
|
|
908
|
-
const state =
|
|
909
|
-
|
|
934
|
+
const state = getItemOptionsState(item.instance.options);
|
|
935
|
+
if (state == null) throw new Error("CodeView.attachItemEditor: instance options are missing their state");
|
|
936
|
+
const onChange = (event) => {
|
|
910
937
|
const latest = this.idToItem.get(state.id);
|
|
911
938
|
if (latest == null) return;
|
|
912
|
-
|
|
913
|
-
item: latest.item,
|
|
914
|
-
file,
|
|
915
|
-
lineAnnotations
|
|
916
|
-
};
|
|
917
|
-
this.options.onItemEditChange?.(latest.item, file, lineAnnotations);
|
|
918
|
-
} });
|
|
919
|
-
if (editor == null) return;
|
|
920
|
-
record = {
|
|
921
|
-
editor,
|
|
922
|
-
state
|
|
939
|
+
this.options.onItemEditChange?.(event, latest.item);
|
|
923
940
|
};
|
|
924
|
-
this.
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
941
|
+
const editStateKey = this.options.getEditStateKey?.(item.item);
|
|
942
|
+
if (item.type === "diff") {
|
|
943
|
+
const editor = createEditor("file-diff", { onChange }, editStateKey);
|
|
944
|
+
createdEditor = editor;
|
|
945
|
+
this.itemEditors.set(id, {
|
|
946
|
+
editor,
|
|
947
|
+
state,
|
|
948
|
+
dispose: editor.edit(item.instance)
|
|
949
|
+
});
|
|
950
|
+
} else {
|
|
951
|
+
const editor = createEditor("file", { onChange }, editStateKey);
|
|
952
|
+
createdEditor = editor;
|
|
953
|
+
this.itemEditors.set(id, {
|
|
954
|
+
editor,
|
|
955
|
+
state,
|
|
956
|
+
dispose: editor.edit(item.instance)
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
} else if (item.type === "diff") record.dispose = record.editor.edit(item.instance);
|
|
960
|
+
else record.dispose = record.editor.edit(item.instance);
|
|
928
961
|
this.attachedEditors.add(id);
|
|
929
962
|
} catch (error) {
|
|
930
|
-
|
|
931
|
-
this.itemEditors.delete(id);
|
|
932
|
-
record.editor.cleanUp();
|
|
933
|
-
}
|
|
963
|
+
createdEditor?.cleanUp();
|
|
934
964
|
this.releaseRenderedItem(item);
|
|
935
965
|
throw error;
|
|
936
966
|
}
|
|
937
967
|
}
|
|
938
968
|
/**
|
|
939
|
-
*
|
|
940
|
-
* off
|
|
941
|
-
*
|
|
942
|
-
*
|
|
969
|
+
* Reconcile the editors CodeView is holding: complete sessions for items
|
|
970
|
+
* whose edit turned off or that were removed, and suspend sessions for
|
|
971
|
+
* collapsed items (the editor tears down, the record and the instance's
|
|
972
|
+
* session stay for the next expand). Attachment happens in the render loop
|
|
973
|
+
* via attachItemEditor.
|
|
943
974
|
*/
|
|
944
975
|
syncItemEditors(removedItems) {
|
|
945
976
|
if (this.itemEditors.size === 0) return;
|
|
@@ -947,25 +978,77 @@ var CodeView = class CodeView {
|
|
|
947
978
|
for (const [id, record] of this.itemEditors) {
|
|
948
979
|
const item = this.idToItem.get(id);
|
|
949
980
|
const removedItem = removedItems?.get(id);
|
|
950
|
-
if (removedItem == null && item != null
|
|
951
|
-
|
|
981
|
+
if (removedItem == null && item != null) {
|
|
982
|
+
const { edit = false, collapsed = false } = item.item;
|
|
983
|
+
if (edit) {
|
|
984
|
+
if (collapsed && this.attachedEditors.delete(id)) record.editor.cleanUp("recycle");
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
} else if (removedItem != null) record.state.removedItem = removedItem.item;
|
|
952
988
|
this.itemEditors.delete(id);
|
|
953
989
|
this.attachedEditors.delete(id);
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
990
|
+
completions.push(record);
|
|
991
|
+
}
|
|
992
|
+
if (completions.length === 0) return;
|
|
993
|
+
let failed = false;
|
|
994
|
+
let failure;
|
|
995
|
+
for (const record of completions) {
|
|
996
|
+
try {
|
|
997
|
+
record.dispose();
|
|
998
|
+
} catch (error) {
|
|
999
|
+
if (!failed) {
|
|
1000
|
+
failed = true;
|
|
1001
|
+
failure = error;
|
|
960
1002
|
}
|
|
961
|
-
finishEditSessionForDiff(itemSnapshot.fileDiff);
|
|
962
1003
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
item: item.item
|
|
966
|
-
});
|
|
1004
|
+
const item = this.idToItem.get(record.state.id);
|
|
1005
|
+
if (item != null) this.markItemLayoutDirty(item);
|
|
967
1006
|
}
|
|
968
|
-
|
|
1007
|
+
this.render();
|
|
1008
|
+
if (failed) throw failure;
|
|
1009
|
+
}
|
|
1010
|
+
requireItemFromState(state) {
|
|
1011
|
+
const item = this.idToItem.get(state.id)?.item ?? state.removedItem;
|
|
1012
|
+
if (item == null) throw new Error(`CodeView.onItemEditComplete: unknown item "${state.id}"`);
|
|
1013
|
+
return item;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Item-instance `onEditComplete` adapter for file items: builds the
|
|
1017
|
+
* accepted next item, hands it to `onItemEditComplete` alongside the event
|
|
1018
|
+
* and the owning item, and translates the identity of the returned item to
|
|
1019
|
+
* the component return contract.
|
|
1020
|
+
*/
|
|
1021
|
+
completeFileItemEdit(state, event) {
|
|
1022
|
+
const item = this.requireItemFromState(state);
|
|
1023
|
+
if (item.type !== "file") throw new Error(`CodeView.onItemEditComplete: item "${state.id}" is not a file item`);
|
|
1024
|
+
const nextItem = {
|
|
1025
|
+
...item,
|
|
1026
|
+
file: event.file,
|
|
1027
|
+
annotations: event.lineAnnotations,
|
|
1028
|
+
edit: false,
|
|
1029
|
+
version: (item.version ?? 0) + 1
|
|
1030
|
+
};
|
|
1031
|
+
if ((this.options.onItemEditComplete?.(event, item, nextItem) ?? "reject") === "reject") return "reject";
|
|
1032
|
+
if (this.idToItem.has(item.id)) this.updateItem(nextItem);
|
|
1033
|
+
return "accept";
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Item-instance `onEditComplete` adapter for diff items; see
|
|
1037
|
+
* completeFileItemEdit.
|
|
1038
|
+
*/
|
|
1039
|
+
completeDiffItemEdit(state, event) {
|
|
1040
|
+
const item = this.requireItemFromState(state);
|
|
1041
|
+
if (item.type !== "diff") throw new Error(`CodeView.onItemEditComplete: item "${state.id}" is not a diff item`);
|
|
1042
|
+
const nextItem = {
|
|
1043
|
+
...item,
|
|
1044
|
+
fileDiff: event.fileDiff,
|
|
1045
|
+
annotations: event.lineAnnotations,
|
|
1046
|
+
edit: false,
|
|
1047
|
+
version: (item.version ?? 0) + 1
|
|
1048
|
+
};
|
|
1049
|
+
if ((this.options.onItemEditComplete?.(event, item, nextItem) ?? "reject") === "reject") return "reject";
|
|
1050
|
+
if (this.idToItem.has(item.id)) this.updateItem(nextItem);
|
|
1051
|
+
return "accept";
|
|
969
1052
|
}
|
|
970
1053
|
renamePendingScrollTarget(oldId, newId) {
|
|
971
1054
|
const { pendingScrollTarget } = this;
|
|
@@ -987,6 +1070,12 @@ var CodeView = class CodeView {
|
|
|
987
1070
|
if (state == null) return;
|
|
988
1071
|
return this.getItemOptions(state, "file")?.item.collapsed;
|
|
989
1072
|
});
|
|
1073
|
+
defineItemOption(prototype, "onEditComplete", (receiver) => {
|
|
1074
|
+
if (this.options.onItemEditComplete == null) return;
|
|
1075
|
+
const state = getItemOptionsState(receiver);
|
|
1076
|
+
if (state == null) return;
|
|
1077
|
+
return (event) => this.completeFileItemEdit(state, event);
|
|
1078
|
+
});
|
|
990
1079
|
for (const key of CODE_VIEW_SHARED_CALLBACK_KEYS) this.defineItemSharedCallback(prototype, "file", key);
|
|
991
1080
|
for (const key of CODE_VIEW_SELECTION_CALLBACK_KEYS) this.defineItemSelectionCallback(prototype, "file", key);
|
|
992
1081
|
return prototype;
|
|
@@ -1001,6 +1090,12 @@ var CodeView = class CodeView {
|
|
|
1001
1090
|
if (state == null) return;
|
|
1002
1091
|
return this.getItemOptions(state, "diff")?.item.collapsed;
|
|
1003
1092
|
});
|
|
1093
|
+
defineItemOption(prototype, "onEditComplete", (receiver) => {
|
|
1094
|
+
if (this.options.onItemEditComplete == null) return;
|
|
1095
|
+
const state = getItemOptionsState(receiver);
|
|
1096
|
+
if (state == null) return;
|
|
1097
|
+
return (event) => this.completeDiffItemEdit(state, event);
|
|
1098
|
+
});
|
|
1004
1099
|
for (const key of CODE_VIEW_SHARED_CALLBACK_KEYS) this.defineItemSharedCallback(prototype, "diff", key);
|
|
1005
1100
|
for (const key of CODE_VIEW_SELECTION_CALLBACK_KEYS) this.defineItemSelectionCallback(prototype, "diff", key);
|
|
1006
1101
|
return prototype;
|
|
@@ -1598,7 +1693,10 @@ var CodeView = class CodeView {
|
|
|
1598
1693
|
syncPagedScrollScaffolding(windowSpecs) {
|
|
1599
1694
|
this.syncContainerHeight();
|
|
1600
1695
|
const stickyBounds = this.getStickyBounds(windowSpecs);
|
|
1601
|
-
if (stickyBounds == null)
|
|
1696
|
+
if (stickyBounds == null) {
|
|
1697
|
+
this.stickyOffset.style.height = `${this.getPagedLayoutTop(windowSpecs.top)}px`;
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1602
1700
|
this.applyStickyPositioning(stickyBounds);
|
|
1603
1701
|
}
|
|
1604
1702
|
reconcileRenderedItems(updatedItems) {
|
|
@@ -1910,11 +2008,8 @@ var CodeView = class CodeView {
|
|
|
1910
2008
|
const item = this.items[index];
|
|
1911
2009
|
if (item == null) throw new Error("CodeView.recomputeLayout: invalid item index");
|
|
1912
2010
|
item.top = runningTop;
|
|
1913
|
-
if (item.type === "diff")
|
|
1914
|
-
|
|
1915
|
-
if (fileDiff != null) Object.assign(item.item.fileDiff, fileDiff);
|
|
1916
|
-
item.height = item.instance.prepareCodeViewItem(item.item.fileDiff, runningTop, reset, item.item.annotations ?? []);
|
|
1917
|
-
} else item.height = item.instance.prepareCodeViewItem(item.item.file, runningTop, reset, item.item.annotations ?? []);
|
|
2011
|
+
if (item.type === "diff") item.height = item.instance.updateCodeViewLayout(item.item.fileDiff, runningTop, reset, item.item.annotations ?? []);
|
|
2012
|
+
else item.height = item.instance.updateCodeViewLayout(item.item.file, runningTop, reset, item.item.annotations ?? []);
|
|
1918
2013
|
runningTop += item.height;
|
|
1919
2014
|
if (index < this.items.length - 1) runningTop += layout.gap;
|
|
1920
2015
|
}
|
|
@@ -1935,8 +2030,8 @@ var CodeView = class CodeView {
|
|
|
1935
2030
|
};
|
|
1936
2031
|
function prepareItemInstance(item) {
|
|
1937
2032
|
item.instance.cleanUp(true);
|
|
1938
|
-
if (item.type === "diff") return item.instance.
|
|
1939
|
-
else return item.instance.
|
|
2033
|
+
if (item.type === "diff") return item.instance.updateCodeViewLayout(item.item.fileDiff, item.top, void 0, item.item.annotations ?? []);
|
|
2034
|
+
else return item.instance.updateCodeViewLayout(item.item.file, item.top, void 0, item.item.annotations ?? []);
|
|
1940
2035
|
}
|
|
1941
2036
|
function shouldClearPool(previousOptions, nextOptions) {
|
|
1942
2037
|
return !areThemesEqual(previousOptions.theme ?? DEFAULT_THEMES, nextOptions.theme ?? DEFAULT_THEMES) || (previousOptions.themeType ?? "system") !== (nextOptions.themeType ?? "system") || previousOptions.unsafeCSS !== nextOptions.unsafeCSS;
|