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()) {