From e84ddb6cfc97f88bbd7aa6adb9e493da58a53a34 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 16 Nov 2025 18:23:45 +0800 Subject: [PATCH] Fix environment variable copy reliability by validating clipboard operation (#2833) * Initial plan * Fix env variable copy issue by using onCopy callback Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- src/components/copy.tsx | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/components/copy.tsx b/src/components/copy.tsx index 2070d9da..522aa194 100644 --- a/src/components/copy.tsx +++ b/src/components/copy.tsx @@ -1,6 +1,6 @@ import intl from 'react-intl-universal'; import React, { useRef, useState, useEffect } from 'react'; -import { Tooltip, Typography } from 'antd'; +import { Tooltip, Typography, message } from 'antd'; import { CopyOutlined, CheckOutlined } from '@ant-design/icons'; import { CopyToClipboard } from 'react-copy-to-clipboard'; @@ -10,16 +10,21 @@ const Copy = ({ text }: { text: string }) => { const [copied, setCopied] = useState(false); const copyIdRef = useRef(); - const copyText = (e?: React.MouseEvent) => { + const handleCopy = (text: string, result: boolean) => { + if (result) { + setCopied(true); + message.success(intl.get('复制成功')); + + cleanCopyId(); + copyIdRef.current = window.setTimeout(() => { + setCopied(false); + }, 3000); + } + }; + + const handleClick = (e?: React.MouseEvent) => { e?.preventDefault(); e?.stopPropagation(); - - setCopied(true); - - cleanCopyId(); - copyIdRef.current = window.setTimeout(() => { - setCopied(false); - }, 3000); }; const cleanCopyId = () => { @@ -27,8 +32,8 @@ const Copy = ({ text }: { text: string }) => { }; return ( - - + +