Skip to content

Commit

Permalink
Fix #4103 Macro boundary in AST-based new macro def
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Dec 21, 2023
1 parent 4b31a99 commit 7450d55
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/preview/math/mathpreviewlib/newcommandfinder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode'
import * as path from 'path'
import type * as Ast from '@unified-latex/unified-latex-types'
import * as Ast from '@unified-latex/unified-latex-types'
import { lw } from '../../../lw'

const logger = lw.log('Preview', 'Math')
Expand Down Expand Up @@ -55,8 +55,15 @@ function parseAst(content: string, node: Ast.Node): string[] {
// \newcommand{\fix}[3][]{\chdeleted{#2}\chadded[comment={#1}]{#3}}
// \newcommand\WARNING{\textcolor{red}{WARNING}}
const start = node.position?.start.offset ?? 0
const lastArg = args[args.length - 1]
const end = lastArg.content[lastArg.content.length - 1].position?.end.offset ?? -1
let lastArg = args[args.length - 1]
let lastContent = lastArg.content[lastArg.content.length - 1]
let closeBraceOffset = 0
while (lastContent.type === 'macro' && lastContent.args && lastContent.args.length > 0) {
closeBraceOffset += lastArg.closeMark.length
lastArg = lastContent.args[lastContent.args.length - 1]
lastContent = lastArg.content[lastArg.content.length - 1]
}
const end = (lastArg.content[lastArg.content.length - 1].position?.end.offset ?? -1 - closeBraceOffset) + closeBraceOffset
macros.push(content.slice(start, end + 1))
}

Expand Down

0 comments on commit 7450d55

Please sign in to comment.