diff --git a/CHANGELOG.md b/CHANGELOG.md index 65a25ee0..cb3e48de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Please note that when exporting to HTML, `stylesdir` and `stylesheet` will be us **NOTE:** We strongly recommend to use [`.asciidoctorconfig` file](https://intellij-asciidoc-plugin.ahus1.de/docs/users-guide/features/advanced/asciidoctorconfig-file.html) to define common attributes. This file will be used in the preview and when exporting to HTML and PDF (using `asciidoctor-pdf`). +### Improvements + +- provide folding for list of sibling attributes by @apupier (#719) + ### Bug fixes - declare `supports_templates` as attribute otherwise `backendTraits` overrides other values, as a result syntax highlighting wasn't working anymore! (#666) diff --git a/src/features/foldingProvider.ts b/src/features/foldingProvider.ts index 022fc70c..07083dad 100644 --- a/src/features/foldingProvider.ts +++ b/src/features/foldingProvider.ts @@ -123,11 +123,40 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange } } + private static handleMultiAttributesFoldingRanges (multiAttributesIndexes: any[], foldingRanges: any[], lineIndex: number, lineText: string, documentLineCount: number) { + if (lineText.startsWith(':')) { + if (multiAttributesIndexes.length === 0) { + multiAttributesIndexes.push(lineIndex) + } + if (lineIndex >= documentLineCount - 1) { + // Attribute on last line of the document + const startIndex = multiAttributesIndexes.pop() + if (lineIndex > startIndex) { + foldingRanges.push(new vscode.FoldingRange( + startIndex, + lineIndex) + ) + } + } + } else { + if (multiAttributesIndexes.length !== 0) { + const startIndex = multiAttributesIndexes.pop() + const endIndex = lineIndex - 1 + if (endIndex > startIndex) { + foldingRanges.push(new vscode.FoldingRange( + startIndex, + endIndex)) + } + } + } + } + private static getBlockFoldingRanges (document: vscode.TextDocument) { const foldingRanges = [] const openBlockIndexes = [] const commentBlockIndexes = [] const singleLineCommentStartIndexes = [] + const multiAttributesIndexes = [] const documentLineCount = document.lineCount for (let lineIndex = 0; lineIndex < documentLineCount; lineIndex++) { const line = document.lineAt(lineIndex) @@ -135,6 +164,7 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange this.handleOpenBlockFoldingRanges(openBlockIndexes, foldingRanges, lineIndex, lineText, documentLineCount) this.handleCommentBlockFoldingRanges(commentBlockIndexes, foldingRanges, lineIndex, lineText, documentLineCount) this.handleSingleLineCommentFoldingRanges(singleLineCommentStartIndexes, foldingRanges, lineIndex, lineText, documentLineCount) + this.handleMultiAttributesFoldingRanges(multiAttributesIndexes, foldingRanges, lineIndex, lineText, documentLineCount) } return foldingRanges } diff --git a/src/test/foldingProvider.test.ts b/src/test/foldingProvider.test.ts index 1a9221ca..4253d2e5 100644 --- a/src/test/foldingProvider.test.ts +++ b/src/test/foldingProvider.test.ts @@ -394,6 +394,24 @@ this is the same paragraph`) ]) }) }) + + suite('getMultiAttributesFoldingRanges', () => { + test('Should fold on a group of attributes ', () => { + const folds = getFoldsForDocument( + `this is a paragraph + +:attribute1: value 1 +:attribute2: value 2 +:attribute3: value 3 +:attribute4: value 4 + +this is a paragraph`) + assert.strictEqual(folds.length, 1, 'expecting 1 fold') + assert.deepStrictEqual(folds, [ + new vscode.FoldingRange(2, 5), + ]) + }) + }) }) function getFoldsForDocument (contents: string) {