Try to keep one blank line after markdown block element folds

Fixes #58187
This commit is contained in:
Matt Bierner
2018-09-07 13:48:44 -07:00
parent a118676a3b
commit 2806df93e4
2 changed files with 17 additions and 2 deletions

View File

@@ -88,7 +88,10 @@ export default class MarkdownFoldingProvider implements vscode.FoldingRangeProvi
const multiLineListItems = tokens.filter(isFoldableToken);
return multiLineListItems.map(listItem => {
const start = listItem.map[0];
const end = listItem.map[1] - 1;
let end = listItem.map[1] - 1;
if (document.lineAt(end).isEmptyOrWhitespace && end >= start + 1) {
end = end - 1;
}
return new vscode.FoldingRange(start, end);
});
}

View File

@@ -114,7 +114,7 @@ d`);
assert.strictEqual(firstFold.end, 3);
});
test('Should fold if list has multiple lines of content', async () => {
test('lists folds should span multiple lines of content', async () => {
const folds = await getFoldsForDocument(`a
- This list item\n spans multiple\n lines.`);
assert.strictEqual(folds.length, 1);
@@ -123,6 +123,18 @@ d`);
assert.strictEqual(firstFold.end, 3);
});
test('List should leave single blankline before new element', async () => {
const folds = await getFoldsForDocument(`- a
a
b`);
assert.strictEqual(folds.length, 1);
const firstFold = folds[0];
assert.strictEqual(firstFold.start, 0);
assert.strictEqual(firstFold.end, 3);
});
test('Should fold fenced code blocks', async () => {
const folds = await getFoldsForDocument(`~~~ts
a