Browse Source

[cm6] Move figure paste handler to core LaTeX extensions (#14957)

GitOrigin-RevId: 2dd6b036c5e9122a7e7564d4246f10444ba593e3
Alf Eaton 3 năm trước cách đây
mục cha
commit
cb1b5b7d54

+ 3 - 0
services/web/frontend/js/features/source-editor/extensions/figure-modal.ts

@@ -202,6 +202,9 @@ export const figureModalPasteHandler = (): Extension => {
       if (!evt.clipboardData || evt.clipboardData.files.length === 0) {
       if (!evt.clipboardData || evt.clipboardData.files.length === 0) {
         return
         return
       }
       }
+      if (evt.clipboardData.types.includes('text/plain')) {
+        return // allow pasted text to be handled even if there's also a file on the clipboard
+      }
       const file = evt.clipboardData.files[0]
       const file = evt.clipboardData.files[0]
       if (!ALLOWED_MIME_TYPES.has(file.type)) {
       if (!ALLOWED_MIME_TYPES.has(file.type)) {
         return
         return

+ 0 - 2
services/web/frontend/js/features/source-editor/extensions/visual/visual.ts

@@ -19,7 +19,6 @@ import { restoreScrollPosition } from '../scroll-position'
 import { CurrentDoc } from '../../../../../../types/current-doc'
 import { CurrentDoc } from '../../../../../../types/current-doc'
 import isValidTeXFile from '../../../../main/is-valid-tex-file'
 import isValidTeXFile from '../../../../main/is-valid-tex-file'
 import { listItemMarker } from './list-item-marker'
 import { listItemMarker } from './list-item-marker'
-import { figureModalPasteHandler } from '../figure-modal'
 import { isSplitTestEnabled } from '../../../../utils/splitTestUtils'
 import { isSplitTestEnabled } from '../../../../utils/splitTestUtils'
 import { toolbarPanel } from '../toolbar/toolbar-panel'
 import { toolbarPanel } from '../toolbar/toolbar-panel'
 import { selectDecoratedArgument } from './select-decorated-argument'
 import { selectDecoratedArgument } from './select-decorated-argument'
@@ -204,7 +203,6 @@ const extension = (options: Options) => [
   isSplitTestEnabled('source-editor-toolbar') ? [] : toolbarPanel(),
   isSplitTestEnabled('source-editor-toolbar') ? [] : toolbarPanel(),
   selectDecoratedArgument,
   selectDecoratedArgument,
   showContentWhenParsed,
   showContentWhenParsed,
-  figureModalPasteHandler(),
   isSplitTestEnabled('paste-html') ? pasteHtml : [],
   isSplitTestEnabled('paste-html') ? pasteHtml : [],
   isSplitTestEnabled('table-generator') ? tableGeneratorTheme : [],
   isSplitTestEnabled('table-generator') ? tableGeneratorTheme : [],
 ]
 ]

+ 5 - 1
services/web/frontend/js/features/source-editor/languages/latex/index.ts

@@ -16,7 +16,10 @@ import importOverleafModules from '../../../../../macros/import-overleaf-module.
 import { documentOutline } from './document-outline'
 import { documentOutline } from './document-outline'
 import { LaTeXLanguage } from './latex-language'
 import { LaTeXLanguage } from './latex-language'
 import { documentEnvironmentNames } from './document-environment-names'
 import { documentEnvironmentNames } from './document-environment-names'
-import { figureModal } from '../../extensions/figure-modal'
+import {
+  figureModal,
+  figureModalPasteHandler,
+} from '../../extensions/figure-modal'
 
 
 const completionSources: CompletionSource[] = [
 const completionSources: CompletionSource[] = [
   ...argumentCompletionSources,
   ...argumentCompletionSources,
@@ -44,5 +47,6 @@ export const latex = () => {
       })
       })
     ),
     ),
     figureModal(),
     figureModal(),
+    figureModalPasteHandler(),
   ])
   ])
 }
 }

+ 31 - 0
services/web/frontend/stories/source-editor/source-editor.stories.tsx

@@ -35,12 +35,43 @@ export const Latex = (args: any, { globals: { theme } }: any) => {
       sharejs_doc: mockDoc(content.tex, changes.tex),
       sharejs_doc: mockDoc(content.tex, changes.tex),
       open_doc_name: 'example.tex',
       open_doc_name: 'example.tex',
     },
     },
+    rootFolder: {
+      name: 'rootFolder',
+      id: 'root-folder-id',
+      type: 'folder',
+      children: [
+        {
+          name: 'example.tex.tex',
+          id: 'example-doc-id',
+          type: 'doc',
+          selected: false,
+          $$hashKey: 'object:89',
+        },
+        {
+          name: 'frog.jpg',
+          id: 'frog-image-id',
+          type: 'file',
+          linkedFileData: null,
+          created: '2023-05-04T16:11:04.352Z',
+          $$hashKey: 'object:108',
+        },
+      ],
+      selected: false,
+    },
     settings: {
     settings: {
       ...settings,
       ...settings,
       overallTheme: theme === 'default-' ? '' : theme,
       overallTheme: theme === 'default-' ? '' : theme,
     },
     },
   })
   })
 
 
+  useMeta({
+    'ol-showSymbolPalette': true,
+    'ol-splitTestVariants': {
+      'figure-modal': 'enabled',
+      'table-generator': 'enabled',
+    },
+  })
+
   return <SourceEditor />
   return <SourceEditor />
 }
 }