Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug when innerChanges is not defined. #185340

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/vs/editor/browser/widget/diffEditorWidget2/diffModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ export class DiffModel extends Disposable implements IDiffEditorViewModel {
if (!diff) {
return;
}
if (!this._showMoves.get()) {
const textEdits = TextEditInfo.fromModelContentChanges(e.changes);
this._lastDiff = applyModifiedEdits(this._lastDiff!, textEdits, model.original, model.modified);

const textEdits = TextEditInfo.fromModelContentChanges(e.changes);
const result = applyModifiedEdits(this._lastDiff!, textEdits, model.original, model.modified);
if (result) {
this._lastDiff = result;
this._diff.set(DiffState.fromDiffResult(this._lastDiff), undefined);
const currentSyncedMovedText = this.syncedMovedTexts.get();
this.syncedMovedTexts.set(currentSyncedMovedText ? this._lastDiff.moves.find(m => m.lineRangeMapping.modifiedRange.intersect(currentSyncedMovedText.lineRangeMapping.modifiedRange)) : undefined, undefined);
Expand All @@ -70,13 +72,16 @@ export class DiffModel extends Disposable implements IDiffEditorViewModel {
if (!diff) {
return;
}
if (!this._showMoves.get()) {
const textEdits = TextEditInfo.fromModelContentChanges(e.changes);
this._lastDiff = applyOriginalEdits(this._lastDiff!, textEdits, model.original, model.modified);

const textEdits = TextEditInfo.fromModelContentChanges(e.changes);
const result = applyModifiedEdits(this._lastDiff!, textEdits, model.original, model.modified);
if (result) {
this._lastDiff = result;
this._diff.set(DiffState.fromDiffResult(this._lastDiff), undefined);
const currentSyncedMovedText = this.syncedMovedTexts.get();
this.syncedMovedTexts.set(currentSyncedMovedText ? this._lastDiff.moves.find(m => m.lineRangeMapping.modifiedRange.intersect(currentSyncedMovedText.lineRangeMapping.modifiedRange)) : undefined, undefined);
}

debouncer.schedule();
}));

Expand Down Expand Up @@ -107,8 +112,8 @@ export class DiffModel extends Disposable implements IDiffEditorViewModel {
computeMoves: this._showMoves.read(reader),
});

result = applyOriginalEdits(result, originalTextEditInfos, model.original, model.modified);
result = applyModifiedEdits(result, modifiedTextEditInfos, model.original, model.modified);
result = applyOriginalEdits(result, originalTextEditInfos, model.original, model.modified) ?? result;
result = applyModifiedEdits(result, modifiedTextEditInfos, model.original, model.modified) ?? result;

const newUnchangedRegions = UnchangedRegion.fromDiffs(result.changes, model.original.getLineCount(), model.modified.getLineCount());

Expand Down Expand Up @@ -327,13 +332,16 @@ export class UnchangedRegion {
}
}

function applyOriginalEdits(diff: IDocumentDiff, textEdits: TextEditInfo[], originalTextModel: ITextModel, modifiedTextModel: ITextModel): IDocumentDiff {
function applyOriginalEdits(diff: IDocumentDiff, textEdits: TextEditInfo[], originalTextModel: ITextModel, modifiedTextModel: ITextModel): IDocumentDiff | undefined {
if (textEdits.length === 0) {
return diff;
}

const diff2 = flip(diff);
const diff3 = applyModifiedEdits(diff2, textEdits, modifiedTextModel, originalTextModel);
if (!diff3) {
return undefined;
}
return flip(diff3);
}

Expand All @@ -346,10 +354,14 @@ function flip(diff: IDocumentDiff): IDocumentDiff {
};
}

function applyModifiedEdits(diff: IDocumentDiff, textEdits: TextEditInfo[], originalTextModel: ITextModel, modifiedTextModel: ITextModel): IDocumentDiff {
function applyModifiedEdits(diff: IDocumentDiff, textEdits: TextEditInfo[], originalTextModel: ITextModel, modifiedTextModel: ITextModel): IDocumentDiff | undefined {
if (textEdits.length === 0) {
return diff;
}
if (diff.changes.some(c => !c.innerChanges) || diff.moves.length > 0) {
// TODO support these cases
return undefined;
}

const changes = applyModifiedEditsToLineRangeMappings(diff.changes, textEdits, originalTextModel, modifiedTextModel);

Expand Down