Skip to content

Commit

Permalink
Merge pull request #4534 from James-Yu/4527-dtx-env-folding
Browse files Browse the repository at this point in the history
Improve doctex folding
  • Loading branch information
James-Yu authored Feb 21, 2025
2 parents 3dc5dc6 + 10c79cd commit 2874f91
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/language/folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,21 @@ export class DoctexFoldingProvider extends FoldingProvider {
keyword,
index: match.index
}
const lastItem = opStack[opStack.length - 1]

if ((match[4] || match[6] || match[8] || match[10] || match[12]) && lastItem && lastItem.keyword === item.keyword) { // match 'end' with its 'begin'
const lastLineTune: number = match[10] || match[12] ? 0 : -1
opStack.pop()
ranges.push(new vscode.FoldingRange(
document.positionAt(lastItem.index).line,
document.positionAt(item.index).line + lastLineTune
))
if (match[4] || match[6] || match[8] || match[10] || match[12]) {
// We have found a closing item
for (let openingIndex = opStack.length - 1; openingIndex >= 0; openingIndex--) {
const openingItem = opStack[openingIndex]
if (openingItem && openingItem.keyword === item.keyword) { // match 'end' with its 'begin'
const lastLineTune: number = match[10] || match[12] ? 0 : -1
ranges.push(new vscode.FoldingRange(
document.positionAt(openingItem.index).line,
document.positionAt(item.index).line + lastLineTune
))
opStack.splice(openingIndex, 1)
break
}
}
} else {
opStack.push(item)
}
Expand Down

0 comments on commit 2874f91

Please sign in to comment.