Skip to content

Commit

Permalink
Fixes #40926: Inherit visibility from the previous line
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Dec 30, 2020
1 parent 95cfa9e commit 3564f18
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/vs/editor/common/viewModel/splitLinesCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,8 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
return null;
}

let hiddenAreas = this.getHiddenAreas();
let isInHiddenArea = false;
let testPosition = new Position(fromLineNumber, 1);
for (const hiddenArea of hiddenAreas) {
if (hiddenArea.containsPosition(testPosition)) {
isInHiddenArea = true;
break;
}
}
// cannot use this.getHiddenAreas() because those decorations have already seen the effect of this model change
const isInHiddenArea = (fromLineNumber > 2 && !this.lines[fromLineNumber - 2].isVisible());

let outputFromLineNumber = (fromLineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(fromLineNumber - 2) + 1);

Expand Down
32 changes: 32 additions & 0 deletions src/vs/editor/test/common/viewModel/viewModelImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,36 @@ suite('ViewModel', () => {
assert.deepEqual(actual, 'line2\r\nline3\r\nline4\r\n');
});
});

test('issue #40926: Incorrect spacing when inserting new line after multiple folded blocks of code', () => {
testViewModel(
[
'foo = {',
' foobar: function() {',
' this.foobar();',
' },',
' foobar: function() {',
' this.foobar();',
' },',
' foobar: function() {',
' this.foobar();',
' },',
'}',
], {}, (viewModel, model) => {
viewModel.setHiddenAreas([
new Range(3, 1, 3, 1),
new Range(6, 1, 6, 1),
new Range(9, 1, 9, 1),
]);

model.applyEdits([
{ range: new Range(4, 7, 4, 7), text: '\n ' },
{ range: new Range(7, 7, 7, 7), text: '\n ' },
{ range: new Range(10, 7, 10, 7), text: '\n ' }
]);

assert.strictEqual(viewModel.getLineCount(), 11);
}
);
});
});

0 comments on commit 3564f18

Please sign in to comment.