mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Merge pull request #184165 from microsoft/hediet/b/line-range-bug-fix
Fixes line range mapping construction bug.
This commit is contained in:
commit
6d45c3610a
|
@ -280,19 +280,23 @@ export function getLineRangeMapping(rangeMapping: RangeMapping, originalLines: s
|
||||||
|
|
||||||
// rangeMapping describes the edit that replaces `rangeMapping.originalRange` with `newText := getText(modifiedLines, rangeMapping.modifiedRange)`.
|
// rangeMapping describes the edit that replaces `rangeMapping.originalRange` with `newText := getText(modifiedLines, rangeMapping.modifiedRange)`.
|
||||||
|
|
||||||
// original: xxx[ \n <- this line is not modified
|
|
||||||
// modified: xxx[ \n
|
|
||||||
if (rangeMapping.modifiedRange.startColumn - 1 >= modifiedLines[rangeMapping.modifiedRange.startLineNumber - 1].length
|
|
||||||
&& rangeMapping.originalRange.startColumn - 1 >= originalLines[rangeMapping.originalRange.startLineNumber - 1].length) {
|
|
||||||
lineStartDelta = 1; // +1 is always possible, as startLineNumber < endLineNumber + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// original: ]xxx \n <- this line is not modified
|
// original: ]xxx \n <- this line is not modified
|
||||||
// modified: ]xx \n
|
// modified: ]xx \n
|
||||||
if (rangeMapping.modifiedRange.endColumn === 1 && rangeMapping.originalRange.endColumn === 1
|
if (rangeMapping.modifiedRange.endColumn === 1 && rangeMapping.originalRange.endColumn === 1
|
||||||
&& rangeMapping.originalRange.startLineNumber + lineStartDelta <= rangeMapping.originalRange.endLineNumber
|
&& rangeMapping.originalRange.startLineNumber + lineStartDelta <= rangeMapping.originalRange.endLineNumber
|
||||||
&& rangeMapping.modifiedRange.startLineNumber + lineStartDelta <= rangeMapping.modifiedRange.endLineNumber) {
|
&& rangeMapping.modifiedRange.startLineNumber + lineStartDelta <= rangeMapping.modifiedRange.endLineNumber) {
|
||||||
lineEndDelta = -1; // We can only do this if the range is not empty yet
|
// We can only do this if the range is not empty yet
|
||||||
|
lineEndDelta = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// original: xxx[ \n <- this line is not modified
|
||||||
|
// modified: xxx[ \n
|
||||||
|
if (rangeMapping.modifiedRange.startColumn - 1 >= modifiedLines[rangeMapping.modifiedRange.startLineNumber - 1].length
|
||||||
|
&& rangeMapping.originalRange.startColumn - 1 >= originalLines[rangeMapping.originalRange.startLineNumber - 1].length
|
||||||
|
&& rangeMapping.originalRange.startLineNumber <= rangeMapping.originalRange.endLineNumber + lineEndDelta
|
||||||
|
&& rangeMapping.modifiedRange.startLineNumber <= rangeMapping.modifiedRange.endLineNumber + lineEndDelta) {
|
||||||
|
// We can only do this if the range is not empty yet
|
||||||
|
lineStartDelta = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalLineRange = new LineRange(
|
const originalLineRange = new LineRange(
|
||||||
|
|
|
@ -9,8 +9,7 @@ import { RangeMapping } from 'vs/editor/common/diff/linesDiffComputer';
|
||||||
import { getLineRangeMapping } from 'vs/editor/common/diff/standardLinesDiffComputer';
|
import { getLineRangeMapping } from 'vs/editor/common/diff/standardLinesDiffComputer';
|
||||||
|
|
||||||
suite('lineRangeMapping', () => {
|
suite('lineRangeMapping', () => {
|
||||||
test('lineRangeMapping', () => {
|
test('1', () => {
|
||||||
// {[2,1 -> 3,1]->[2,1 -> 2,1]}
|
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
getLineRangeMapping(
|
getLineRangeMapping(
|
||||||
new RangeMapping(
|
new RangeMapping(
|
||||||
|
@ -27,7 +26,29 @@ suite('lineRangeMapping', () => {
|
||||||
''
|
''
|
||||||
]
|
]
|
||||||
).toString(),
|
).toString(),
|
||||||
"{[3,4)->[3,3)}"
|
"{[2,3)->[2,2)}"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('2', () => {
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
getLineRangeMapping(
|
||||||
|
new RangeMapping(
|
||||||
|
new Range(2, 1, 2, 1),
|
||||||
|
new Range(2, 1, 4, 1),
|
||||||
|
),
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
]
|
||||||
|
).toString(),
|
||||||
|
"{[2,2)->[2,4)}"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue