diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts b/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts index 3a90a7d4fe..035fdf98c7 100644 --- a/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts +++ b/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts @@ -188,13 +188,19 @@ export const atomicDecorations = (options: Options) => { currentOrdinal = ordinalStack.pop() ?? 0 } + let seenDocumentEnvironment = false + tree.iterate({ enter(nodeRef) { if (nodeRef.node.type.is('Maketitle')) { preamble.to = nodeRef.node.from } else if (nodeRef.node.type.is('DocumentEnvironment')) { - preamble.to = - nodeRef.node.getChild('Content')?.from ?? nodeRef.node.from + // only count the first instance of DocumentEnvironment + if (!seenDocumentEnvironment) { + preamble.to = + nodeRef.node.getChild('Content')?.from ?? nodeRef.node.from + seenDocumentEnvironment = true + } } else if (nodeRef.node.type.is('Title')) { const node = nodeRef.node.getChild('TextArgument') if (node) {