Просмотр исходного кода

Merge pull request #33994 from overleaf/mj-command-palette-synctex

[web] Add synctex to command palette

GitOrigin-RevId: 10e769dae6088d279d010fcfa3577b489c6ff89c
Mathias Jakobsen 2 месяцев назад
Родитель
Сommit
cc762bb7e6

+ 2 - 0
services/web/frontend/js/features/command-palette/hooks/use-command-registry-source.tsx

@@ -18,6 +18,8 @@ const ENABLED_COMMANDS: string[] = [
   'compile',
   'stop-compile',
   'recompile-from-scratch',
+  'synctex-sync-to-pdf',
+  'synctex-sync-to-code',
 ]
 
 const useCommandRegistrySource = (): CommandPaletteSource => {

+ 37 - 0
services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.tsx

@@ -11,6 +11,7 @@ import useSynctex from '../hooks/use-synctex'
 import { useFeatureFlag } from '@/shared/context/split-test-context'
 import OLSpinner from '@/shared/components/ol/ol-spinner'
 import { sendMB } from '@/infrastructure/event-tracking'
+import { useCommandProvider } from '@/features/ide-react/hooks/use-command-provider'
 
 const GoToCodeButton = memo(function GoToCodeButton({
   syncToCode,
@@ -22,6 +23,24 @@ const GoToCodeButton = memo(function GoToCodeButton({
   isDetachLayout?: boolean
 }) {
   const { t } = useTranslation()
+  useCommandProvider(
+    () => [
+      {
+        id: 'synctex-sync-to-code',
+        handler: () => {
+          sendMB('jump-to-location', {
+            method: 'command',
+            direction: 'pdf-location-in-code',
+          })
+          syncToCode({ visualOffset: 72 })
+        },
+        disabled: syncToCodeInFlight,
+        label: t('go_to_pdf_location_in_code'),
+      },
+    ],
+    [t, syncToCode, syncToCodeInFlight]
+  )
+
   const buttonClasses = classNames('synctex-control', {
     'detach-synctex-control': !!isDetachLayout,
   })
@@ -98,6 +117,24 @@ const GoToPdfButton = memo(function GoToPdfButton({
     syncToPdf()
   }, [syncToPdf])
 
+  useCommandProvider(
+    () => [
+      {
+        id: 'synctex-sync-to-pdf',
+        handler: () => {
+          sendMB('jump-to-location', {
+            method: 'command',
+            direction: 'code-location-in-pdf',
+          })
+          syncToPdf()
+        },
+        label: t('go_to_code_location_in_pdf'),
+        disabled: syncToPdfInFlight || !canSyncToPdf,
+      },
+    ],
+    [t, syncToPdf, syncToPdfInFlight, canSyncToPdf]
+  )
+
   let buttonIcon = null
   if (syncToPdfInFlight) {
     buttonIcon = <OLSpinner size="sm" />