From 8ea4e8c03ac9d3587f592366d31a60f064aecd68 Mon Sep 17 00:00:00 2001 From: Roman Rodionov Date: Wed, 31 Jan 2024 16:25:20 +0100 Subject: [PATCH] #3967 - Exception if you paste from clipboard using Ctrl+Alt+V (Smile insert) - added fallback to old clipboard api for smarts --- .../src/script/ui/state/hotkeys.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/ketcher-react/src/script/ui/state/hotkeys.ts b/packages/ketcher-react/src/script/ui/state/hotkeys.ts index 7513110cff..1ee6e1cd71 100644 --- a/packages/ketcher-react/src/script/ui/state/hotkeys.ts +++ b/packages/ketcher-react/src/script/ui/state/hotkeys.ts @@ -354,13 +354,23 @@ async function safelyGetMimeType( async function getStructStringFromClipboardData( data: ClipboardItem[], ): Promise { - const clipboardItem = data[0] as ClipboardItem; - const structStr = - (await safelyGetMimeType(clipboardItem, `web ${ChemicalMimeType.KET}`)) || - (await safelyGetMimeType(clipboardItem, `web ${ChemicalMimeType.Mol}`)) || - (await safelyGetMimeType(clipboardItem, `web ${ChemicalMimeType.Rxn}`)) || - (await safelyGetMimeType(clipboardItem, 'text/plain')); - return structStr === '' ? '' : structStr.text(); + const clipboardItem = data[0]; + + if (clipboardItem instanceof ClipboardItem) { + const structStr = + (await safelyGetMimeType(clipboardItem, `web ${ChemicalMimeType.KET}`)) || + (await safelyGetMimeType(clipboardItem, `web ${ChemicalMimeType.Mol}`)) || + (await safelyGetMimeType(clipboardItem, `web ${ChemicalMimeType.Rxn}`)) || + (await safelyGetMimeType(clipboardItem, 'text/plain')); + return structStr === '' ? '' : structStr.text(); + } else { + return ( + data[ChemicalMimeType.KET] || + data[ChemicalMimeType.Mol] || + data[ChemicalMimeType.Rxn] || + data['text/plain'] + ); + } } function isAbleToCopy(editor: Editor): boolean {