From d7a8e7999b7631bf21f393e6669ab9c959e562ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mime=20=C4=8Cuvalo?= Date: Fri, 26 Apr 2024 14:44:32 +0100 Subject: [PATCH] copy/paste: fix pasting not working from Edit menu --- .../src/lib/ui/hooks/useClipboardEvents.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/tldraw/src/lib/ui/hooks/useClipboardEvents.ts b/packages/tldraw/src/lib/ui/hooks/useClipboardEvents.ts index b26f39ab4..933f36ef4 100644 --- a/packages/tldraw/src/lib/ui/hooks/useClipboardEvents.ts +++ b/packages/tldraw/src/lib/ui/hooks/useClipboardEvents.ts @@ -74,13 +74,12 @@ const INPUTS = ['input', 'select', 'textarea'] * @param editor - The editor instance. * @internal */ -function disallowClipboardEvents(editor: Editor) { +function disallowClipboardEvents() { const { activeElement } = document return ( - editor.getIsMenuOpen() || - (activeElement && - (activeElement.getAttribute('contenteditable') || - INPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1)) + activeElement && + (activeElement.getAttribute('contenteditable') || + INPUTS.indexOf(activeElement.tagName.toLowerCase()) > -1) ) } @@ -584,7 +583,7 @@ export function useMenuClipboardEvents() { // If we're editing a shape, or we are focusing an editable input, then // we would want the user's paste interaction to go to that element or // input instead; e.g. when pasting text into a text shape's content - if (editor.getEditingShapeId() !== null || disallowClipboardEvents(editor)) return + if (editor.getEditingShapeId() !== null || disallowClipboardEvents()) return if (Array.isArray(data) && data[0] instanceof ClipboardItem) { handlePasteFromClipboardApi(editor, data, point) @@ -621,7 +620,7 @@ export function useNativeClipboardEvents() { if ( editor.getSelectedShapeIds().length === 0 || editor.getEditingShapeId() !== null || - disallowClipboardEvents(editor) + disallowClipboardEvents() ) { return } @@ -635,7 +634,7 @@ export function useNativeClipboardEvents() { if ( editor.getSelectedShapeIds().length === 0 || editor.getEditingShapeId() !== null || - disallowClipboardEvents(editor) + disallowClipboardEvents() ) { return } @@ -664,7 +663,7 @@ export function useNativeClipboardEvents() { // If we're editing a shape, or we are focusing an editable input, then // we would want the user's paste interaction to go to that element or // input instead; e.g. when pasting text into a text shape's content - if (editor.getEditingShapeId() !== null || disallowClipboardEvents(editor)) return + if (editor.getEditingShapeId() !== null || disallowClipboardEvents()) return // First try to use the clipboard data on the event if (e.clipboardData && !editor.inputs.shiftKey) {