markdown toc should include full span to next header

The folding range should exclude blank lines before the next header level
This commit is contained in:
Matt Bierner
2018-08-24 12:01:06 +02:00
parent 30d0a61a8f
commit 49edd3d038
2 changed files with 7 additions and 5 deletions

View File

@@ -56,6 +56,12 @@ export default class MarkdownFoldingProvider implements vscode.FoldingRangeProvi
private async getHeaderFoldingRanges(document: vscode.TextDocument) {
const tocProvider = new TableOfContentsProvider(this.engine, document);
const toc = await tocProvider.getToc();
return toc.map((entry) => new vscode.FoldingRange(entry.line, entry.location.range.end.line));
return toc.map(entry => {
let endLine = entry.location.range.end.line;
if (document.lineAt(endLine).isEmptyOrWhitespace && endLine >= entry.line + 1) {
endLine = endLine - 1;
}
return new vscode.FoldingRange(entry.line, endLine);
});
}
}