diff --git a/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts b/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts index 54fbe97f3a..947280b8eb 100644 --- a/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts +++ b/services/web/frontend/js/features/source-editor/utils/tree-operations/commands.ts @@ -191,3 +191,21 @@ export const enterNode = ( }) } } + +const texOrPdfArgument = { tex: 0, pdf: 1 } + +export const texOrPdfString = ( + state: EditorState, + node: SyntaxNode, + version: keyof typeof texOrPdfArgument +) => { + const commandName = getCommandName(node.node, state, ['CtrlSeq']) + if (commandName === '\\texorpdfstring') { + const argumentNode = node + .getChildren('TextArgument') + [texOrPdfArgument[version]]?.getChild('LongArg') + if (argumentNode) { + return state.doc.sliceString(argumentNode.from, argumentNode.to) + } + } +} diff --git a/services/web/frontend/js/features/source-editor/utils/tree-operations/outline.ts b/services/web/frontend/js/features/source-editor/utils/tree-operations/outline.ts index 97b094483d..b1fda8aa5b 100644 --- a/services/web/frontend/js/features/source-editor/utils/tree-operations/outline.ts +++ b/services/web/frontend/js/features/source-editor/utils/tree-operations/outline.ts @@ -4,6 +4,7 @@ import { NodeIntersectsChangeFn, ProjectionItem } from './projection' import * as tokens from '../../lezer-latex/latex.terms.mjs' import { getEnvironmentArguments, getEnvironmentName } from './environments' import { PartialFlatOutline } from '@/features/ide-react/context/outline-context' +import { texOrPdfString } from './commands' export type Outline = { line: number @@ -89,18 +90,10 @@ const getEntryText = (state: EditorState, node: SyntaxNodeRef): string => { } // Handle the texorpdfstring command - if ( - token.type.name === 'Command' && - token.node.firstChild?.firstChild != null - ) { - let command = token.node.firstChild.firstChild - let commandName = state.doc.sliceString(command.from + 1, command.to) - let textArguments = token.node.firstChild.getChildren('TextArgument') - if (commandName == 'texorpdfstring' && textArguments.length >= 2) { - let pdfstring = textArguments[1] - titleParts.push( - state.doc.sliceString(pdfstring.from + 1, pdfstring.to - 1) - ) + if (token.type.is('UnknownCommand')) { + const pdfString = texOrPdfString(state, token.node, 'pdf') + if (pdfString) { + titleParts.push(pdfString) return false } }