From cee9d2f923c6bef9f82775a724661cefbf363dcc Mon Sep 17 00:00:00 2001 From: Aaron Shumway Date: Mon, 8 May 2017 21:22:57 -0600 Subject: [PATCH] Don't include trailing empty lines from end of code folding --- src/vs/editor/common/model/indentRanges.ts | 5 +++-- src/vs/editor/test/common/model/indentRanges.test.ts | 4 ++-- src/vs/editor/test/common/model/textModel.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/vs/editor/common/model/indentRanges.ts b/src/vs/editor/common/model/indentRanges.ts index f220df0cfbab5..b37cba59ac3ae 100644 --- a/src/vs/editor/common/model/indentRanges.ts +++ b/src/vs/editor/common/model/indentRanges.ts @@ -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 { diff --git a/src/vs/editor/test/common/model/indentRanges.test.ts b/src/vs/editor/test/common/model/indentRanges.test.ts index f65722224b9be..a0a75cc13eccf 100644 --- a/src/vs/editor/test/common/model/indentRanges.test.ts +++ b/src/vs/editor/test/common/model/indentRanges.test.ts @@ -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', () => { @@ -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)]); }); }); diff --git a/src/vs/editor/test/common/model/textModel.test.ts b/src/vs/editor/test/common/model/textModel.test.ts index cba2a056ebae1..2bc5b3f08c138 100644 --- a/src/vs/editor/test/common/model/textModel.test.ts +++ b/src/vs/editor/test/common/model/textModel.test.ts @@ -914,7 +914,7 @@ suite('TextModel.getLineIndentGuide', () => { [1, ' '], [1, ' return 1;'], [1, ' }'], - [1, ' '], + [0, ' '], [0, '}'], ]); }); @@ -927,7 +927,7 @@ suite('TextModel.getLineIndentGuide', () => { [2, '\t \t//hello'], [2, '\t return 2;'], [1, ' \t}'], - [1, ' '], + [0, ' '], [0, '}'], ]); });