Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include trailing empty lines at end of code folding #26258

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/vs/editor/common/model/indentRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ export function computeRanges(model: ITextModel, minimumRangeSize: number = 1):

for (let line = model.getLineCount(); line > 0; line--) {
let indent = model.getIndentLevel(line);
let previous = previousRegions[previousRegions.length - 1];
if (indent === -1) {
// exclude empty lines from end of fold
previous.line = line;
continue; // only whitespace
}

let previous = previousRegions[previousRegions.length - 1];

if (previous.indent > indent) {
// discard all regions with larger indent
do {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/test/common/model/indentRanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ suite('Indentation Folding', () => {
/* 6*/ ' }',
/* 7*/ ' ',
/* 8*/ '}',
], [r(1, 7, 0), r(3, 5, 2)]);
], [r(1, 6, 0), r(3, 5, 2)]);
});

test('Fold Tabs', () => {
Expand All @@ -112,6 +112,6 @@ suite('Indentation Folding', () => {
/* 6*/ ' \t}',
/* 7*/ ' ',
/* 8*/ '}',
], [r(1, 7, 0), r(3, 5, 4)]);
], [r(1, 6, 0), r(3, 5, 4)]);
});
});
4 changes: 2 additions & 2 deletions src/vs/editor/test/common/model/textModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ suite('TextModel.getLineIndentGuide', () => {
[1, ' '],
[1, ' return 1;'],
[1, ' }'],
[1, ' '],
[0, ' '],
[0, '}'],
]);
});
Expand All @@ -927,7 +927,7 @@ suite('TextModel.getLineIndentGuide', () => {
[2, '\t \t//hello'],
[2, '\t return 2;'],
[1, ' \t}'],
[1, ' '],
[0, ' '],
[0, '}'],
]);
});
Expand Down