mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-26 13:19:42 +00:00
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:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,14 +65,10 @@ export class TableOfContentsProvider {
|
||||
|
||||
// Get full range of section
|
||||
return toc.map((entry, startIndex): TocEntry => {
|
||||
const start = entry.line;
|
||||
let end: number | undefined = undefined;
|
||||
for (let i = startIndex + 1; i < toc.length; ++i) {
|
||||
if (toc[i].level <= entry.level) {
|
||||
end = toc[i].line - 1;
|
||||
if (document.lineAt(end).isEmptyOrWhitespace && end >= start + 1) {
|
||||
end = end - 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user