From 488d0fdf9ed88b3acb0d7e0965c9543057625803 Mon Sep 17 00:00:00 2001 From: Rebeka Dekany <50901361+rebekadekany@users.noreply.github.com> Date: Mon, 14 Jul 2025 17:54:03 +0200 Subject: [PATCH] Preserve source-only extensions on file switch (#27080) GitOrigin-RevId: 661c70b78a508619e6532b87b0409f546b4d9e82 --- .../test/create-and-compile-project.spec.ts | 10 +++++-- server-ce/test/editor.spec.ts | 5 +++- server-ce/test/project-sharing.spec.ts | 27 +++++++++++++++---- server-ce/test/sandboxed-compiles.spec.ts | 8 ++++-- .../source-editor/extensions/index.ts | 2 +- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/server-ce/test/create-and-compile-project.spec.ts b/server-ce/test/create-and-compile-project.spec.ts index 959a3be107..a0e03fe8d0 100644 --- a/server-ce/test/create-and-compile-project.spec.ts +++ b/server-ce/test/create-and-compile-project.spec.ts @@ -40,9 +40,15 @@ describe('Project creation and compilation', function () { cy.get('.cm-line').should('have.length', 1) cy.get('.cm-line').type(markdownContent) cy.findByText('main.tex').click() - cy.get('.cm-content').should('contain.text', '\\maketitle') + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'contain.text', + '\\maketitle' + ) cy.findByText(fileName).click() - cy.get('.cm-content').should('contain.text', markdownContent) + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'contain.text', + markdownContent + ) }) it('can link and display linked image from other project', function () { diff --git a/server-ce/test/editor.spec.ts b/server-ce/test/editor.spec.ts index f8f7f0f53c..d0060518de 100644 --- a/server-ce/test/editor.spec.ts +++ b/server-ce/test/editor.spec.ts @@ -104,7 +104,10 @@ describe('editor', () => { force: true, }) cy.get('button').contains('𝜉').click() - cy.get('.cm-content').should('contain.text', '\\xi') + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'contain.text', + '\\xi' + ) cy.log('recompile to force flush and avoid "unsaved changes" prompt') recompile() diff --git a/server-ce/test/project-sharing.spec.ts b/server-ce/test/project-sharing.spec.ts index e26439264b..4da2209332 100644 --- a/server-ce/test/project-sharing.spec.ts +++ b/server-ce/test/project-sharing.spec.ts @@ -55,8 +55,15 @@ describe('Project Sharing', function () { function expectContentReadOnlyAccess() { cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/) - cy.get('.cm-content').should('contain.text', '\\maketitle') - cy.get('.cm-content').should('have.attr', 'contenteditable', 'false') + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'contain.text', + '\\maketitle' + ) + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'have.attr', + 'contenteditable', + 'false' + ) } function expectContentWriteAccess() { @@ -64,13 +71,23 @@ describe('Project Sharing', function () { cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/) const recompile = throttledRecompile() // wait for the editor to finish loading - cy.get('.cm-content').should('contain.text', '\\maketitle') + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'contain.text', + '\\maketitle' + ) // the editor should be writable - cy.get('.cm-content').should('have.attr', 'contenteditable', 'true') + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'have.attr', + 'contenteditable', + 'true' + ) cy.findByText('\\maketitle').parent().click() cy.findByText('\\maketitle').parent().type(`\n\\section{{}${section}}`) // should have written - cy.get('.cm-content').should('contain.text', `\\section{${section}}`) + cy.findByRole('textbox', { name: /Source Editor editing/i }).should( + 'contain.text', + `\\section{${section}}` + ) // check PDF recompile() cy.get('.pdf-viewer').should('contain.text', projectName) diff --git a/server-ce/test/sandboxed-compiles.spec.ts b/server-ce/test/sandboxed-compiles.spec.ts index 62c87384d6..71f5b43392 100644 --- a/server-ce/test/sandboxed-compiles.spec.ts +++ b/server-ce/test/sandboxed-compiles.spec.ts @@ -161,7 +161,9 @@ describe('SandboxedCompiles', function () { }) cy.log('navigate to Section A') - cy.get('.cm-content').within(() => cy.findByText('Section A').click()) + cy.findByRole('textbox', { name: /Source Editor editing/i }).within( + () => cy.findByText('Section A').click() + ) cy.get('[aria-label="Go to code location in PDF"]').click() cy.get('@title').then((title: any) => { waitUntilScrollingFinished('.pdfjs-viewer-inner', title) @@ -170,7 +172,9 @@ describe('SandboxedCompiles', function () { }) cy.log('navigate to Section B') - cy.get('.cm-content').within(() => cy.findByText('Section B').click()) + cy.findByRole('textbox', { name: /Source Editor editing/i }).within( + () => cy.findByText('Section B').click() + ) cy.get('[aria-label="Go to code location in PDF"]').click() cy.get('@sectionA').then((title: any) => { waitUntilScrollingFinished('.pdfjs-viewer-inner', title) diff --git a/services/web/frontend/js/features/source-editor/extensions/index.ts b/services/web/frontend/js/features/source-editor/extensions/index.ts index f7ab774d15..9471bb5aad 100644 --- a/services/web/frontend/js/features/source-editor/extensions/index.ts +++ b/services/web/frontend/js/features/source-editor/extensions/index.ts @@ -80,7 +80,7 @@ export const createExtensions = (options: Record): Extension[] => [ // A built-in extension that enables soft line wrapping. EditorView.lineWrapping, sourceOnly( - options.visual, + options.visual.visual, EditorView.contentAttributes.of({ 'aria-label': 'Source Editor editing' }) ), // A built-in extension that re-indents input if the language defines an indentOnInput field in its language data.