Skip to content

Commit d171766

Browse files
authored
1 parent 6bc77ae commit d171766

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

src/vs/editor/browser/widget/diffEditorWidget2/diffEditorViewModel.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,18 @@ export class UnchangedRegion {
289289
let modStart = mapping.modifiedRange.startLineNumber;
290290
let length = mapping.originalRange.length;
291291

292-
if (origStart === 1 && modStart === 1 && length > minContext + minHiddenLineCount) {
293-
if (length < originalLineCount) {
292+
const atStart = origStart === 1 && modStart === 1;
293+
const atEnd = origStart + length === originalLineCount + 1 && modStart + length === modifiedLineCount + 1;
294+
295+
if ((atStart || atEnd) && length > minContext + minHiddenLineCount) {
296+
if (atStart && !atEnd) {
297+
length -= minContext;
298+
}
299+
if (atEnd && !atStart) {
300+
origStart += minContext;
301+
modStart += minContext;
294302
length -= minContext;
295303
}
296-
result.push(new UnchangedRegion(origStart, modStart, length, 0, 0));
297-
} else if (origStart + length === originalLineCount + 1 && modStart + length === modifiedLineCount + 1 && length > minContext + minHiddenLineCount) {
298-
origStart += minContext;
299-
modStart += minContext;
300-
length -= minContext;
301304
result.push(new UnchangedRegion(origStart, modStart, length, 0, 0));
302305
} else if (length > minContext * 2 + minHiddenLineCount) {
303306
origStart += minContext;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import assert = require('assert');
7+
import { UnchangedRegion } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorViewModel';
8+
import { LineRange } from 'vs/editor/common/core/lineRange';
9+
import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer';
10+
11+
suite('DiffEditorWidget2', () => {
12+
suite('UnchangedRegion', () => {
13+
function serialize(regions: UnchangedRegion[]): unknown {
14+
return regions.map(r => `${r.originalRange} - ${r.modifiedRange}`);
15+
}
16+
17+
test('Everything changed', () => {
18+
assert.deepStrictEqual(serialize(UnchangedRegion.fromDiffs(
19+
[new LineRangeMapping(new LineRange(1, 10), new LineRange(1, 10), [])],
20+
10,
21+
10,
22+
)), []);
23+
});
24+
25+
test('Nothing changed', () => {
26+
assert.deepStrictEqual(serialize(UnchangedRegion.fromDiffs(
27+
[],
28+
10,
29+
10,
30+
)), [
31+
"[1,11) - [1,11)"
32+
]);
33+
});
34+
35+
test('Change in the middle', () => {
36+
assert.deepStrictEqual(serialize(UnchangedRegion.fromDiffs(
37+
[new LineRangeMapping(new LineRange(50, 60), new LineRange(50, 60), [])],
38+
100,
39+
100,
40+
)), ([
41+
'[1,47) - [1,47)',
42+
'[63,101) - [63,101)'
43+
]));
44+
});
45+
46+
test('Change at the end', () => {
47+
assert.deepStrictEqual(serialize(UnchangedRegion.fromDiffs(
48+
[new LineRangeMapping(new LineRange(99, 100), new LineRange(100, 100), [])],
49+
100,
50+
100,
51+
)), (["[1,96) - [1,96)"]));
52+
});
53+
});
54+
});

0 commit comments

Comments
 (0)