From 8967fe34e531b39b77c24685097898bbb45dc58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=88=AA=E5=AE=87?= <3364451258@qq.com> Date: Mon, 25 May 2026 18:40:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86=E7=A9=BA=E7=99=BD=E5=8F=8A=E5=8F=8C?= =?UTF-8?q?=E5=87=BB=E7=BC=96=E8=BE=91=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PathEditDialog 添加 useEffect 在打开时同步 initialValue - AppShell 添加 path-dblclick 事件监听,双击路径行打开编辑 Co-Authored-By: Claude Opus 4.7 --- src/components/dialogs/PathEditDialog.tsx | 9 ++++++++- src/components/layout/AppShell.tsx | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/dialogs/PathEditDialog.tsx b/src/components/dialogs/PathEditDialog.tsx index 167b0bd..e8f4326 100644 --- a/src/components/dialogs/PathEditDialog.tsx +++ b/src/components/dialogs/PathEditDialog.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; interface PathEditDialogProps { @@ -13,6 +13,13 @@ export function PathEditDialog({ open, title, initialValue, onConfirm, onCancel const { t } = useTranslation(); const [value, setValue] = useState(initialValue); + // 每次打开时同步 initialValue(解决 React 复用实例导致空白的问题) + useEffect(() => { + if (open) { + setValue(initialValue); + } + }, [open, initialValue]); + if (!open) return null; return ( diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsx index d148b95..0307bd2 100644 --- a/src/components/layout/AppShell.tsx +++ b/src/components/layout/AppShell.tsx @@ -1,4 +1,4 @@ -import { useState, useCallback } from 'react'; +import { useState, useCallback, useEffect } from 'react'; import { useAppStore, type TabId } from '@/store/app-store'; import { useThemeStore } from '@/store/theme-store'; import { useTranslation } from 'react-i18next'; @@ -151,6 +151,18 @@ export function AppShell() { // ── 双击编辑监听 ── + useEffect(() => { + const handler = (e: Event) => { + const detail = (e as CustomEvent).detail; + if (detail && typeof detail.index === 'number') { + const target = getCurrentTarget(); + setEditDialog({ open: true, index: detail.index, value: detail.path, target }); + } + }; + window.addEventListener('path-dblclick', handler); + return () => window.removeEventListener('path-dblclick', handler); + }, [getCurrentTarget]); + const handleNewConfirm = useCallback((value: string) => { setNewDialog(false); if (value.trim()) {