From aef9821e00620bdadaec679fda1abc2bead887c0 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 1 Sep 2023 12:05:06 +0100 Subject: [PATCH] Only end the preamble at MakeTitle if directly inside DocumentEnvironment (#14593) GitOrigin-RevId: 3252a8260e02728c05b753433e3488b799b18de0 --- .../extensions/visual/atomic-decorations.ts | 9 ++++++++- .../codemirror-editor-visual.spec.tsx | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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 fef6b6a887..c20a05cc02 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 @@ -186,7 +186,14 @@ export const atomicDecorations = (options: Options) => { tree.iterate({ enter(nodeRef) { if (nodeRef.node.type.is('Maketitle')) { - preamble.to = nodeRef.node.from + // end the preamble at \maketitle, if it's directly inside the document environment + const parentEnvironment = ancestorOfNodeWithType( + nodeRef.node, + '$Environment' + ) + if (parentEnvironment?.type.is('DocumentEnvironment')) { + preamble.to = nodeRef.node.from + } } else if (nodeRef.node.type.is('DocumentEnvironment')) { // only count the first instance of DocumentEnvironment if (!seenDocumentEnvironment) { diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual.spec.tsx index de71d0518a..6228d1f2b5 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual.spec.tsx @@ -510,6 +510,25 @@ describe(' in Visual mode', function () { cy.get('.ol-cm-preamble-line').eq(3).should('not.exist') }) + it('should exclude maketitle from preamble extents if nested in another environment', function () { + cy.get('@first-line').type( + [ + '\\author{{}Author}', + '\\title{{}Document title}', + '\\begin{{}document}', + '\\begin{{}frame}{{}Foo}', + '\\maketitle', + '\\end{{}frame}', + '\\end{{}document}', + '', + ].join('{Enter}') + ) + cy.get('.ol-cm-preamble-widget').should('have.length', 1) + cy.get('.ol-cm-preamble-widget').click() + + cy.get('.ol-cm-preamble-line').should('have.length', 3) + }) + it('should show multiple authors', function () { cy.get('@first-line').type( [