mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:45:54 +08:00
fix: 修复编辑对话框空白及双击编辑无效的问题
- PathEditDialog 添加 useEffect 在打开时同步 initialValue - AppShell 添加 path-dblclick 事件监听,双击路径行打开编辑 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
interface PathEditDialogProps {
|
interface PathEditDialogProps {
|
||||||
@@ -13,6 +13,13 @@ export function PathEditDialog({ open, title, initialValue, onConfirm, onCancel
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [value, setValue] = useState(initialValue);
|
const [value, setValue] = useState(initialValue);
|
||||||
|
|
||||||
|
// 每次打开时同步 initialValue(解决 React 复用实例导致空白的问题)
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setValue(initialValue);
|
||||||
|
}
|
||||||
|
}, [open, initialValue]);
|
||||||
|
|
||||||
if (!open) return null;
|
if (!open) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useCallback } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import { useAppStore, type TabId } from '@/store/app-store';
|
import { useAppStore, type TabId } from '@/store/app-store';
|
||||||
import { useThemeStore } from '@/store/theme-store';
|
import { useThemeStore } from '@/store/theme-store';
|
||||||
import { useTranslation } from 'react-i18next';
|
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) => {
|
const handleNewConfirm = useCallback((value: string) => {
|
||||||
setNewDialog(false);
|
setNewDialog(false);
|
||||||
if (value.trim()) {
|
if (value.trim()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user