From aae4971a1bec37ea1f606e92fca0614963fab6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 31 Jul 2026 13:38:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=E5=8A=A8?= =?UTF-8?q?=E4=BD=9C=E5=88=86=E5=8F=91=20=E4=BD=BF=E7=94=A8=20switch=20?= =?UTF-8?q?=E6=8C=89=E5=8A=A8=E4=BD=9C=E7=B1=BB=E5=9E=8B=E5=88=86=E5=8F=91?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=E6=93=8D=E4=BD=9C=20?= =?UTF-8?q?=E5=9C=A8=E5=90=84=E5=8A=A8=E4=BD=9C=E5=88=86=E6=94=AF=E5=86=85?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E7=9B=AE=E6=A0=87=E7=B1=BB=E5=9E=8B=E5=92=8C?= =?UTF-8?q?=E5=AA=92=E4=BD=93=E7=B1=BB=E5=9E=8B=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=8A=B6=E6=80=81=E6=9B=B4=E6=96=B0=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=B5=8C=E5=A5=97=E4=B8=89=E5=85=83=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../useRightClickMenu.ts | 78 +++++++++++-------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/src/components/image-editor/EditorAgentConversation/useRightClickMenu.ts b/src/components/image-editor/EditorAgentConversation/useRightClickMenu.ts index e26c667dd..1f20e6d29 100644 --- a/src/components/image-editor/EditorAgentConversation/useRightClickMenu.ts +++ b/src/components/image-editor/EditorAgentConversation/useRightClickMenu.ts @@ -293,38 +293,52 @@ export function useRightClickMenu({ } : current, ); - const succeeded = - action === EditorAgentRightClickAction.CopyText && - target.kind === 'text' - ? await copyTextToClipboard(target.text) - : action === EditorAgentRightClickAction.CopyImage && - target.kind === 'asset' && - target.asset.mediaType === 'image' - ? await copyAssetImage(target.asset) - : action === EditorAgentRightClickAction.ReferenceImage && - target.kind === 'asset' && - target.asset.mediaType === 'image' && - contextAssetMediaSrc(target.asset).trim() - ? (onReferenceImage?.(target.asset) ?? false) - : action === EditorAgentRightClickAction.FocusCanvas && - target.kind === 'asset' - ? focusAssetOnCanvas(target.asset, onFocusResource) - : action === EditorAgentRightClickAction.DownloadAsset && - target.kind === 'asset' - ? await downloadAsset(target.asset) - : false; - setRightClickMenu((current) => - current?.target === target && current.pendingAction === action - ? succeeded - ? null - : { - ...current, - pendingAction: null, - resultAction: action, - result: 'error', - } - : current, - ); + let succeeded = false; + switch (action) { + case EditorAgentRightClickAction.CopyText: + if (target.kind === 'text') { + succeeded = await copyTextToClipboard(target.text); + } + break; + case EditorAgentRightClickAction.CopyImage: + if (target.kind === 'asset' && target.asset.mediaType === 'image') { + succeeded = await copyAssetImage(target.asset); + } + break; + case EditorAgentRightClickAction.ReferenceImage: + if ( + target.kind === 'asset' && + target.asset.mediaType === 'image' && + contextAssetMediaSrc(target.asset).trim() + ) { + succeeded = onReferenceImage?.(target.asset) ?? false; + } + break; + case EditorAgentRightClickAction.FocusCanvas: + if (target.kind === 'asset') { + succeeded = focusAssetOnCanvas(target.asset, onFocusResource); + } + break; + case EditorAgentRightClickAction.DownloadAsset: + if (target.kind === 'asset') { + succeeded = await downloadAsset(target.asset); + } + break; + } + setRightClickMenu((current) => { + if (current?.target !== target || current.pendingAction !== action) { + return current; + } + if (succeeded) { + return null; + } + return { + ...current, + pendingAction: null, + resultAction: action, + result: 'error', + }; + }); }, [onFocusResource, onReferenceImage, rightClickMenu], );