Преглед изворни кода

Preserve source-only extensions on file switch (#27080)

GitOrigin-RevId: 661c70b78a508619e6532b87b0409f546b4d9e82
Rebeka Dekany пре 1 година
родитељ
комит
488d0fdf9e

+ 8 - 2
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 () {

+ 4 - 1
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()

+ 22 - 5
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)

+ 6 - 2
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)

+ 1 - 1
services/web/frontend/js/features/source-editor/extensions/index.ts

@@ -80,7 +80,7 @@ export const createExtensions = (options: Record<string, any>): 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.