From 0cf36ec5deb65cb19fc08ff44ae0db8bbdebf2fa Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 27 Sep 2023 11:49:17 +0100 Subject: [PATCH] [cm6] Move figure paste handler to core LaTeX extensions (#14957) GitOrigin-RevId: 2dd6b036c5e9122a7e7564d4246f10444ba593e3 --- .../source-editor/extensions/figure-modal.ts | 3 ++ .../source-editor/extensions/visual/visual.ts | 2 -- .../source-editor/languages/latex/index.ts | 6 +++- .../source-editor/source-editor.stories.tsx | 31 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/figure-modal.ts b/services/web/frontend/js/features/source-editor/extensions/figure-modal.ts index 325bd74397..04bbff238f 100644 --- a/services/web/frontend/js/features/source-editor/extensions/figure-modal.ts +++ b/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) { 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] if (!ALLOWED_MIME_TYPES.has(file.type)) { return diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/visual.ts b/services/web/frontend/js/features/source-editor/extensions/visual/visual.ts index e33c4ba584..46c8b29143 100644 --- a/services/web/frontend/js/features/source-editor/extensions/visual/visual.ts +++ b/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 isValidTeXFile from '../../../../main/is-valid-tex-file' import { listItemMarker } from './list-item-marker' -import { figureModalPasteHandler } from '../figure-modal' import { isSplitTestEnabled } from '../../../../utils/splitTestUtils' import { toolbarPanel } from '../toolbar/toolbar-panel' import { selectDecoratedArgument } from './select-decorated-argument' @@ -204,7 +203,6 @@ const extension = (options: Options) => [ isSplitTestEnabled('source-editor-toolbar') ? [] : toolbarPanel(), selectDecoratedArgument, showContentWhenParsed, - figureModalPasteHandler(), isSplitTestEnabled('paste-html') ? pasteHtml : [], isSplitTestEnabled('table-generator') ? tableGeneratorTheme : [], ] diff --git a/services/web/frontend/js/features/source-editor/languages/latex/index.ts b/services/web/frontend/js/features/source-editor/languages/latex/index.ts index d2b5a04dec..cc25b9d5b4 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/index.ts +++ b/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 { LaTeXLanguage } from './latex-language' import { documentEnvironmentNames } from './document-environment-names' -import { figureModal } from '../../extensions/figure-modal' +import { + figureModal, + figureModalPasteHandler, +} from '../../extensions/figure-modal' const completionSources: CompletionSource[] = [ ...argumentCompletionSources, @@ -44,5 +47,6 @@ export const latex = () => { }) ), figureModal(), + figureModalPasteHandler(), ]) } diff --git a/services/web/frontend/stories/source-editor/source-editor.stories.tsx b/services/web/frontend/stories/source-editor/source-editor.stories.tsx index 1ce56d0a30..ad5c337abb 100644 --- a/services/web/frontend/stories/source-editor/source-editor.stories.tsx +++ b/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), 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, overallTheme: theme === 'default-' ? '' : theme, }, }) + useMeta({ + 'ol-showSymbolPalette': true, + 'ol-splitTestVariants': { + 'figure-modal': 'enabled', + 'table-generator': 'enabled', + }, + }) + return }