refactor(skill): unify tree selection with VSCode-style single state

Remove redundant createTargetNodeId and use selectedTreeNodeId for both
visual highlight and creation target. This simplifies the state management
by having a single source of truth for tree selection, similar to VSCode's
file explorer behavior where both files and folders can be selected.
This commit is contained in:
yyh
2026-01-19 22:36:04 +08:00
parent 8f4a4214a1
commit 9080607028
6 changed files with 16 additions and 23 deletions

View File

@ -49,13 +49,12 @@ export function useTreeNodeHandlers({
const handleClick = useCallback((e: React.MouseEvent) => {
e.stopPropagation()
storeApi.getState().setCreateTargetNodeId(node.data.id)
node.select()
node.select() // This triggers Tree's onSelect → setSelectedTreeNodeId
if (isFolder)
throttledToggle()
else
handleFileClick()
}, [handleFileClick, isFolder, node, storeApi, throttledToggle])
}, [handleFileClick, isFolder, node, throttledToggle])
const handleDoubleClick = useCallback((e: React.MouseEvent) => {
e.stopPropagation()
@ -74,7 +73,8 @@ export function useTreeNodeHandlers({
e.preventDefault()
e.stopPropagation()
storeApi.getState().setCreateTargetNodeId(node.data.id)
// Select the node for highlight + creation target
storeApi.getState().setSelectedTreeNodeId(node.data.id)
storeApi.getState().setContextMenu({
top: e.clientY,
left: e.clientX,