Skip to content

Commit db418c8

Browse files
authored
Fixes bug in diffing algorithm. (microsoft#157702)
1 parent fa16306 commit db418c8

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/vs/editor/browser/widget/workerBasedDocumentDiffProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class WorkerBasedDocumentDiffProvider implements IDocumentDiffProvider {
2222
}
2323

2424
// Convert from space efficient JSON data to rich objects.
25-
return {
25+
const diff: IDocumentDiff = {
2626
identical: result.identical,
2727
quitEarly: result.quitEarly,
2828
changes: result.changes.map(
@@ -40,5 +40,6 @@ export class WorkerBasedDocumentDiffProvider implements IDocumentDiffProvider {
4040
)
4141
),
4242
};
43+
return diff;
4344
}
4445
}

src/vs/editor/common/diff/algorithms/myersDiffAlgorithm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ class FastInt32Array {
106106
set(idx: number, value: number): void {
107107
if (idx < 0) {
108108
idx = -idx - 1;
109-
if (idx > this.negativeArr.length) {
109+
if (idx >= this.negativeArr.length) {
110110
const arr = this.negativeArr;
111111
this.negativeArr = new Int32Array(arr.length * 2);
112112
this.negativeArr.set(arr);
113113
}
114114
this.negativeArr[idx] = value;
115115
} else {
116-
if (idx > this.positiveArr.length) {
116+
if (idx >= this.positiveArr.length) {
117117
const arr = this.positiveArr;
118118
this.positiveArr = new Int32Array(arr.length * 2);
119119
this.positiveArr.set(arr);

src/vs/editor/common/diff/standardLinesDiffComputer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ export class StandardLinesDiffComputer implements ILinesDiffComputer {
8080
const targetSlice = new Slice(modifiedLines, diff.seq2Range);
8181

8282
const diffs = this.detailedDiffingAlgorithm.compute(sourceSlice, targetSlice);
83-
return diffs.map(
83+
const result = diffs.map(
8484
(d) =>
8585
new RangeMapping(
8686
sourceSlice.translateRange(d.seq1Range).delta(diff.seq1Range.start),
8787
targetSlice.translateRange(d.seq2Range).delta(diff.seq2Range.start)
8888
)
8989
);
90+
return result;
9091
}
9192
}
9293

0 commit comments

Comments
 (0)