@pierre/diffs 1.4.3 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +2 -4
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +23 -12
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +2 -0
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +6 -0
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +18 -1
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +47 -15
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +11 -11
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +18 -17
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts +1 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -3
- package/dist/constants.js.map +1 -1
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +16 -3
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +47 -11
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +20 -13
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +30 -11
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/sprite.d.ts +2 -2
- package/dist/sprite.d.ts.map +1 -1
- package/dist/sprite.js +57 -0
- package/dist/sprite.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.d.ts +5 -4
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.js +32 -9
- package/dist/utils/editSessionHunks.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +21 -13
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/parseQuotedDiffFileName.d.ts +8 -0
- package/dist/utils/parseQuotedDiffFileName.d.ts.map +1 -0
- package/dist/utils/parseQuotedDiffFileName.js +54 -0
- package/dist/utils/parseQuotedDiffFileName.js.map +1 -0
- package/dist/utils/realignChangeContent.d.ts +13 -10
- package/dist/utils/realignChangeContent.d.ts.map +1 -1
- package/dist/utils/realignChangeContent.js +23 -19
- package/dist/utils/realignChangeContent.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +39 -0
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/worker/worker-portable.js +39 -0
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +39 -0
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -502,13 +502,14 @@ var FileDiff = class {
|
|
|
502
502
|
this.expandHunk(hunkIndex, direction, expansionLineCountOverride);
|
|
503
503
|
};
|
|
504
504
|
expandHunk = (hunkIndex, direction, expansionLineCountOverride) => {
|
|
505
|
-
this.hunksRenderer.expandHunk(hunkIndex, direction, expansionLineCountOverride);
|
|
506
505
|
this.loadFilesIfNecessary();
|
|
506
|
+
this.hunksRenderer.expandHunk(hunkIndex, direction, expansionLineCountOverride);
|
|
507
507
|
this.rerender();
|
|
508
508
|
};
|
|
509
509
|
loadFilesIfNecessary() {
|
|
510
510
|
const { fileDiff, options: { loadDiffFiles } } = this;
|
|
511
|
-
if (fileDiff == null ||
|
|
511
|
+
if (fileDiff == null || !canHydrateDiff(fileDiff) || this.pendingFiles?.fileDiff === fileDiff) return;
|
|
512
|
+
if (loadDiffFiles == null) throw new Error("FileDiff: loadDiffFiles is required to load full files for a partial diff");
|
|
512
513
|
const promise = this.loadFilesForDiff(fileDiff, loadDiffFiles);
|
|
513
514
|
const pendingFiles = this.pendingFiles = {
|
|
514
515
|
fileDiff,
|
|
@@ -519,10 +520,41 @@ var FileDiff = class {
|
|
|
519
520
|
};
|
|
520
521
|
pendingFiles.promise = promise.finally(clearPendingFiles);
|
|
521
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* In order to start an edit session, you must be using a `fileDiff` that
|
|
525
|
+
* includes the full contents for both files. In other words, `isPartial`
|
|
526
|
+
* must be false You can use `prepareForEditing` to hydrate if
|
|
527
|
+
* `loadDiffFiles` was passed in to `options`
|
|
528
|
+
*/
|
|
529
|
+
__canAttachEditor() {
|
|
530
|
+
return this.fileDiff != null && !this.fileDiff.isPartial;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Load a partial diff before starting a new edit session. Call this before
|
|
534
|
+
* Editor.edit when the diff may still be partial; it resolves only when this
|
|
535
|
+
* instance has a complete diff to edit.
|
|
536
|
+
*/
|
|
537
|
+
async prepareForEditing() {
|
|
538
|
+
if (this.__canAttachEditor()) return;
|
|
539
|
+
const pending = this.__prepareForEditing();
|
|
540
|
+
if (pending == null) {
|
|
541
|
+
if (this.fileDiff?.isPartial === true && !canHydrateDiff(this.fileDiff)) throw new Error("FileDiff.prepareForEditing: this partial diff cannot be hydrated; provide a complete diff");
|
|
542
|
+
throw new Error("FileDiff.prepareForEditing: a partial diff requires loadDiffFiles");
|
|
543
|
+
}
|
|
544
|
+
await pending;
|
|
545
|
+
if (!this.__canAttachEditor()) throw new Error("FileDiff.prepareForEditing: the diff did not finish loading");
|
|
546
|
+
}
|
|
547
|
+
/** Hydrate a diff if necessary */
|
|
548
|
+
__prepareForEditing() {
|
|
549
|
+
if (this.__canAttachEditor()) return;
|
|
550
|
+
if (this.fileDiff?.isPartial === true && !canHydrateDiff(this.fileDiff)) throw new Error("FileDiff: this partial diff cannot be hydrated; provide a complete diff to edit");
|
|
551
|
+
this.loadFilesIfNecessary();
|
|
552
|
+
return this.pendingFiles?.promise;
|
|
553
|
+
}
|
|
522
554
|
async loadFilesForDiff(fileDiff, loadDiffFiles) {
|
|
523
555
|
try {
|
|
524
556
|
const files = await loadDiffFiles(fileDiff);
|
|
525
|
-
if (
|
|
557
|
+
if (this.fileDiff !== fileDiff) return;
|
|
526
558
|
await this.handleFilesLoaded(fileDiff, files);
|
|
527
559
|
} catch (error) {
|
|
528
560
|
if (this.options.disableErrorHandling === true) throw error;
|
|
@@ -533,7 +565,7 @@ var FileDiff = class {
|
|
|
533
565
|
if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) return;
|
|
534
566
|
hydratePartialDiff("merge", expectedDiff, files);
|
|
535
567
|
this.setHydratedState(files);
|
|
536
|
-
if (this.
|
|
568
|
+
if (this.installHydratedSessionDiff(expectedDiff)) {
|
|
537
569
|
this.rerender();
|
|
538
570
|
return;
|
|
539
571
|
}
|
|
@@ -541,17 +573,14 @@ var FileDiff = class {
|
|
|
541
573
|
if (!this.enabled || this.fileDiff !== expectedDiff) return;
|
|
542
574
|
this.rerender();
|
|
543
575
|
}
|
|
544
|
-
|
|
545
|
-
if (expectedDiff.isPartial) throw new Error("FileDiff.
|
|
576
|
+
installHydratedSessionDiff(expectedDiff) {
|
|
577
|
+
if (expectedDiff.isPartial) throw new Error("FileDiff.installHydratedSessionDiff: diffs cannot be partial for editing");
|
|
546
578
|
if (this.fileDiff !== expectedDiff) return false;
|
|
547
|
-
const { editor } = this;
|
|
548
579
|
if (this.editSession?.outgoingDiff != null) {
|
|
549
580
|
this.installEditSession(expectedDiff);
|
|
550
581
|
return true;
|
|
551
582
|
}
|
|
552
|
-
|
|
553
|
-
this.installEditSession(expectedDiff, editor.__getDocumentContents(getAdditionFile(expectedDiff)), editor.__getDocumentSessionState());
|
|
554
|
-
return true;
|
|
583
|
+
return false;
|
|
555
584
|
}
|
|
556
585
|
updateExternalDiff(incomingExternalDiff, lineAnnotations) {
|
|
557
586
|
if (areDiffTargetsEqual(this.fileDiff, incomingExternalDiff)) return false;
|
|
@@ -561,9 +590,6 @@ var FileDiff = class {
|
|
|
561
590
|
if (incomingExternalDiff.isPartial) this.loadFilesIfNecessary();
|
|
562
591
|
else this.installEditSession(incomingExternalDiff);
|
|
563
592
|
if (this.editSession != null) this.editSession.outgoingDiff = outgoingDiff;
|
|
564
|
-
} else if (this.editor != null) {
|
|
565
|
-
if (incomingExternalDiff.isPartial) this.loadFilesIfNecessary();
|
|
566
|
-
else this.installEditSession(incomingExternalDiff, this.editor.__getDocumentContents(getAdditionFile(incomingExternalDiff)), this.editor.__getDocumentSessionState());
|
|
567
593
|
}
|
|
568
594
|
if (this.editSession?.annotations != null && lineAnnotations != null) {
|
|
569
595
|
this.lineAnnotations = lineAnnotations;
|
|
@@ -747,9 +773,9 @@ var FileDiff = class {
|
|
|
747
773
|
const sync = (highlighter) => {
|
|
748
774
|
if (!this.enabled || this.editor !== editor || this.fileContainer !== fileContainer || this.getLatestDiff() !== fileDiff) return;
|
|
749
775
|
const replacement = this.editSession?.outgoingDiff;
|
|
750
|
-
const externalDiff = this
|
|
776
|
+
const { fileDiff: externalDiff } = this;
|
|
751
777
|
const externalDocument = replacement != null && externalDiff != null && replacement !== fileDiff;
|
|
752
|
-
const resetHistory = externalDocument ? shouldResetUndoState(replacement, externalDiff) : false;
|
|
778
|
+
const resetHistory = externalDocument && replacement != null && externalDiff != null ? shouldResetUndoState(replacement, externalDiff) : false;
|
|
753
779
|
editor.__syncRenderView({
|
|
754
780
|
highlighter,
|
|
755
781
|
fileContainer,
|
|
@@ -846,6 +872,7 @@ var FileDiff = class {
|
|
|
846
872
|
__attachEditor(editor) {
|
|
847
873
|
if (this.type !== "file-diff") throw new Error(`FileDiff.__attachEditor: cannot attach an editor to a "${this.type}" diff`);
|
|
848
874
|
if (this.editor != null) throw new Error("FileDiff.__attachEditor: an editor is already attached");
|
|
875
|
+
if (!this.__canAttachEditor()) throw new Error("FileDiff.__attachEditor: a complete diff is required before editing");
|
|
849
876
|
const detach = () => {
|
|
850
877
|
this.editor = void 0;
|
|
851
878
|
this.finishEditSession();
|
|
@@ -989,6 +1016,11 @@ var FileDiff = class {
|
|
|
989
1016
|
this.rerender();
|
|
990
1017
|
this.interactionManager.setSelectionDirty();
|
|
991
1018
|
}
|
|
1019
|
+
/** Update the private diff without editor DOM, then rehighlight on return. */
|
|
1020
|
+
applySuspendedDocumentChange(textDocument, newLineAnnotations) {
|
|
1021
|
+
this.applyDocumentChange(textDocument, newLineAnnotations);
|
|
1022
|
+
this.hunksRenderer.clearRenderCache();
|
|
1023
|
+
}
|
|
992
1024
|
updateRenderCache(dirtyLines, themeType, options = {}) {
|
|
993
1025
|
const editSessionDiff = this.editSession?.diff;
|
|
994
1026
|
if (editSessionDiff == null) throw new Error("FileDiff.updateRenderCache: requires an active edit session");
|