Skip to content

Commit

Permalink
Update FoldingProvider.sectionRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Sep 9, 2023
1 parent 1c3d13f commit 3335c7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/providers/folding.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import * as vscode from 'vscode'
import type { Manager } from '../components/manager'


export class FoldingProvider implements vscode.FoldingRangeProvider {
private readonly sectionRegex: RegExp[] = []
private sectionRegex: RegExp[]

constructor() {
const sections = vscode.workspace.getConfiguration('latex-toybox').get('view.outline.sections') as string[]
this.sectionRegex = sections.map(section => RegExp(`\\\\(?:${section})(?:\\*)?(?:\\[[^\\[\\]\\{\\}]*\\])?{(.*)}`, 'm'))
constructor(private readonly extension: {
readonly manager: Manager
}) {
this.sectionRegex = this.createSectionRegex()
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('latex-toybox.view.outline.sections', this.extension.manager.getWorkspaceFolderRootDir())) {
this.sectionRegex = this.createSectionRegex()
}
})
}

private createSectionRegex() {
const sections = vscode.workspace.getConfiguration('latex-toybox').get<string[]>('view.outline.sections', [])
return sections.map(section => RegExp(`\\\\(?:${section})(?:\\*)?(?:\\[[^\\[\\]\\{\\}]*\\])?{(.*)}`, 'm'))
}

public provideFoldingRanges(document: vscode.TextDocument): vscode.FoldingRange[] {
Expand Down
2 changes: 1 addition & 1 deletion src/providersmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class ProvidersManager {
)

context.subscriptions.push(
vscode.languages.registerFoldingRangeProvider(latexSelector, new FoldingProvider()),
vscode.languages.registerFoldingRangeProvider(latexSelector, new FoldingProvider(extension)),
)

context.subscriptions.push(
Expand Down

0 comments on commit 3335c7b

Please sign in to comment.