Sfoglia il codice sorgente

Merge pull request #7323 from overleaf/ta-synctex-disable-multi-one-way

Don't Disable Synctex PDF-to-Code Button

GitOrigin-RevId: 90328e0fea8cb5358217ce866839f5e1a4a73b94
Timothée Alby 4 anni fa
parent
commit
a110c4d7bd

+ 4 - 0
services/web/frontend/js/features/file-tree/controllers/file-tree-controller.js

@@ -25,6 +25,10 @@ App.controller(
       )
     })
 
+    $scope.$on('file-tree.reselectDoc', (ev, docId) => {
+      window.dispatchEvent(new CustomEvent('editor.openDoc', { detail: docId }))
+    })
+
     // Set isConnected to true if:
     // - connection state is 'ready', OR
     // - connection state is 'waitingCountdown' and reconnection_countdown is null

+ 1 - 5
services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.js

@@ -23,7 +23,6 @@ function GoToCodeButton({
   syncToCode,
   syncToCodeInFlight,
   isDetachLayout,
-  hasSingleSelectedDoc,
 }) {
   const { t } = useTranslation()
   const tooltipPlacement = isDetachLayout ? 'bottom' : 'right'
@@ -51,7 +50,7 @@ function GoToCodeButton({
         bsStyle="default"
         bsSize="xs"
         onClick={() => syncToCode(position, 72)}
-        disabled={syncToCodeInFlight || !hasSingleSelectedDoc}
+        disabled={syncToCodeInFlight}
         className={buttonClasses}
         aria-label={t('go_to_pdf_location_in_code')}
       >
@@ -367,7 +366,6 @@ function PdfSynctexControls() {
           syncToCode={syncToCode}
           syncToCodeInFlight={syncToCodeInFlight}
           isDetachLayout
-          hasSingleSelectedDoc={hasSingleSelectedDoc}
         />
       </>
     )
@@ -385,7 +383,6 @@ function PdfSynctexControls() {
           position={position}
           syncToCode={syncToCode}
           syncToCodeInFlight={syncToCodeInFlight}
-          hasSingleSelectedDoc={hasSingleSelectedDoc}
         />
       </>
     )
@@ -399,7 +396,6 @@ GoToCodeButton.propTypes = {
   position: PropTypes.object.isRequired,
   syncToCode: PropTypes.func.isRequired,
   syncToCodeInFlight: PropTypes.bool.isRequired,
-  hasSingleSelectedDoc: PropTypes.bool.isRequired,
 }
 
 GoToPdfButton.propTypes = {

+ 1 - 0
services/web/frontend/js/ide/editor/EditorManager.js

@@ -225,6 +225,7 @@ export default EditorManager = (function () {
       if (doc.id === this.$scope.editor.open_doc_id && !options.forceReopen) {
         // automatically update the file tree whenever the file is opened
         this.ide.fileTreeManager.selectEntity(doc)
+        this.$scope.$broadcast('file-tree.reselectDoc', doc.id)
         this.$scope.$apply(() => {
           return done(false)
         })

+ 3 - 18
services/web/test/frontend/components/pdf-preview/pdf-synctex-controls.spec.tsx

@@ -132,10 +132,6 @@ describe('<PdfSynctexControls/>', function () {
     cy.get('body')
       .findByRole('button', { name: 'Go to code location in PDF' })
       .should('be.disabled')
-
-    cy.get('body')
-      .findByRole('button', { name: /^Go to PDF location in code/ })
-      .should('be.disabled')
   })
 
   it('disables button when a file is selected', function () {
@@ -152,10 +148,6 @@ describe('<PdfSynctexControls/>', function () {
     cy.get('body')
       .findByRole('button', { name: 'Go to code location in PDF' })
       .should('be.disabled')
-
-    cy.get('body')
-      .findByRole('button', { name: /^Go to PDF location in code/ })
-      .should('be.disabled')
   })
 
   describe('with detacher role', function () {
@@ -285,16 +277,9 @@ describe('<PdfSynctexControls/>', function () {
 
       cy.wait('@compile')
 
-      cy.get('body')
-        .findByRole('button', { name: /^Go to PDF location in code/ })
-        .should('be.disabled')
-        .then(() => {
-          sysendTestHelper.receiveMessage({
-            role: 'detached',
-            event: 'state-has-single-selected-doc',
-            data: { value: true },
-          })
-        })
+      cy.get('body').findByRole('button', {
+        name: /^Go to PDF location in code/,
+      })
 
       cy.get('body')
         .findByRole('button', { name: /^Go to PDF location in code/ })