提交 10ca8670 编写于 作者: A Alex Dima

Fixes #42751

上级 fc8b4c0d
......@@ -74,16 +74,17 @@ class LineMarkerSequence implements ISequence {
return r + 2;
}
public getCharSequence(startIndex: number, endIndex: number): CharSequence {
public getCharSequence(shouldIgnoreTrimWhitespace: boolean, startIndex: number, endIndex: number): CharSequence {
let charCodes: number[] = [];
let lineNumbers: number[] = [];
let columns: number[] = [];
let len = 0;
for (let index = startIndex; index <= endIndex; index++) {
const startColumn = this._startColumns[index];
const endColumn = this._endColumns[index];
const lineContent = this._lines[index];
const startColumn = (shouldIgnoreTrimWhitespace ? this._startColumns[index] : 1);
const endColumn = (shouldIgnoreTrimWhitespace ? this._endColumns[index] : lineContent.length + 1);
for (let col = startColumn; col < endColumn; col++) {
charCodes[len] = this._lines[index].charCodeAt(col - 1);
charCodes[len] = lineContent.charCodeAt(col - 1);
lineNumbers[len] = index + 1;
columns[len] = col;
len++;
......@@ -254,7 +255,7 @@ class LineChange implements ILineChange {
this.charChanges = charChanges;
}
public static createFromDiffResult(diffChange: IDiffChange, originalLineSequence: LineMarkerSequence, modifiedLineSequence: LineMarkerSequence, continueProcessingPredicate: () => boolean, shouldPostProcessCharChanges: boolean): LineChange {
public static createFromDiffResult(shouldIgnoreTrimWhitespace: boolean, diffChange: IDiffChange, originalLineSequence: LineMarkerSequence, modifiedLineSequence: LineMarkerSequence, continueProcessingPredicate: () => boolean, shouldPostProcessCharChanges: boolean): LineChange {
let originalStartLineNumber: number;
let originalEndLineNumber: number;
let modifiedStartLineNumber: number;
......@@ -278,8 +279,8 @@ class LineChange implements ILineChange {
}
if (diffChange.originalLength !== 0 && diffChange.modifiedLength !== 0 && continueProcessingPredicate()) {
const originalCharSequence = originalLineSequence.getCharSequence(diffChange.originalStart, diffChange.originalStart + diffChange.originalLength - 1);
const modifiedCharSequence = modifiedLineSequence.getCharSequence(diffChange.modifiedStart, diffChange.modifiedStart + diffChange.modifiedLength - 1);
const originalCharSequence = originalLineSequence.getCharSequence(shouldIgnoreTrimWhitespace, diffChange.originalStart, diffChange.originalStart + diffChange.originalLength - 1);
const modifiedCharSequence = modifiedLineSequence.getCharSequence(shouldIgnoreTrimWhitespace, diffChange.modifiedStart, diffChange.modifiedStart + diffChange.modifiedLength - 1);
let rawChanges = computeDiff(originalCharSequence, modifiedCharSequence, continueProcessingPredicate, true);
......@@ -379,7 +380,7 @@ export class DiffComputer {
if (this.shouldIgnoreTrimWhitespace) {
let lineChanges: LineChange[] = [];
for (let i = 0, length = rawChanges.length; i < length; i++) {
lineChanges.push(LineChange.createFromDiffResult(rawChanges[i], this.original, this.modified, this._continueProcessingPredicate.bind(this), this.shouldPostProcessCharChanges));
lineChanges.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, rawChanges[i], this.original, this.modified, this._continueProcessingPredicate.bind(this), this.shouldPostProcessCharChanges));
}
return lineChanges;
}
......@@ -454,7 +455,7 @@ export class DiffComputer {
if (nextChange) {
// Emit the actual change
result.push(LineChange.createFromDiffResult(nextChange, this.original, this.modified, this._continueProcessingPredicate.bind(this), this.shouldPostProcessCharChanges));
result.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, nextChange, this.original, this.modified, this._continueProcessingPredicate.bind(this), this.shouldPostProcessCharChanges));
originalLineIndex += nextChange.originalLength;
modifiedLineIndex += nextChange.modifiedLength;
......
......@@ -679,7 +679,7 @@ suite('Editor Diff - DiffComputer', () => {
' * `yarn [install]` -- Install project NPM dependencies. This is automatically done when you first create the project. You should only need to run this if you add dependencies in `package.json`.',
];
let modified = [
' * `yarn` -- Install project NPM dependencies. You should only need to run this if you add dependencies in `package.json`.',
' * `yarn` -- Install project NPM dependencies. You should only need to run this if you add dependencies in `package.json`.',
];
let expected = [
createLineChange(
......@@ -692,4 +692,24 @@ suite('Editor Diff - DiffComputer', () => {
];
assertDiff(original, modified, expected, true, false);
});
test('issue #42751', () => {
let original = [
' 1',
' 2',
];
let modified = [
' 1',
' 3',
];
let expected = [
createLineChange(
2, 2, 2, 2,
[
createCharChange(2, 3, 2, 4, 2, 3, 2, 5)
]
)
];
assertDiff(original, modified, expected, true, false);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册