From aa68d3b8dba78f9184976c0002eea45a4acb4aac Mon Sep 17 00:00:00 2001 From: balibabu Date: Tue, 12 Nov 2024 15:49:45 +0800 Subject: [PATCH] fix: Cannot copy and paste text on agent page #3356 (#3357) ### What problem does this PR solve? fix: Cannot copy and paste text on agent page #3356 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/pages/flow/hooks.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/web/src/pages/flow/hooks.ts b/web/src/pages/flow/hooks.ts index aa89832af..f6faf69d3 100644 --- a/web/src/pages/flow/hooks.ts +++ b/web/src/pages/flow/hooks.ts @@ -23,7 +23,7 @@ import { useDebounceEffect } from 'ahooks'; import { FormInstance, message } from 'antd'; import dayjs from 'dayjs'; import { humanId } from 'human-id'; -import { lowerFirst } from 'lodash'; +import { get, lowerFirst } from 'lodash'; import trim from 'lodash/trim'; import { useTranslation } from 'react-i18next'; import { useParams } from 'umi'; @@ -641,6 +641,8 @@ export const useCopyPaste = () => { const onCopyCapture = useCallback( (event: ClipboardEvent) => { + if (get(event, 'srcElement.tagName') !== 'BODY') return; + event.preventDefault(); const nodesStr = JSON.stringify( nodes.filter((n) => n.selected && n.data.label !== Operator.Begin), @@ -653,11 +655,12 @@ export const useCopyPaste = () => { const onPasteCapture = useCallback( (event: ClipboardEvent) => { - event.preventDefault(); const nodes = JSON.parse( event.clipboardData?.getData('agent:nodes') || '[]', ) as Node[] | undefined; - if (nodes) { + + if (Array.isArray(nodes) && nodes.length) { + event.preventDefault(); nodes.forEach((n) => { duplicateNode(n.id, n.data.label); });