Skip to content

Commit

Permalink
fix: Cannot copy and paste text on agent page #3356 (#3357)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
cike8899 authored Nov 12, 2024
1 parent 784ae89 commit aa68d3b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions web/src/pages/flow/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand All @@ -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);
});
Expand Down

0 comments on commit aa68d3b

Please sign in to comment.