Fix sidebar reselection after dragging non-selelected item or renaming

This commit is contained in:
Gregory Schier
2025-11-03 06:19:04 -08:00
parent 1dfc2ee602
commit 236c8fa656

View File

@@ -57,7 +57,7 @@ import { InlineCode } from './core/InlineCode';
import type { InputHandle } from './core/Input'; import type { InputHandle } from './core/Input';
import { Input } from './core/Input'; import { Input } from './core/Input';
import { LoadingIcon } from './core/LoadingIcon'; import { LoadingIcon } from './core/LoadingIcon';
import { collapsedFamily, isSelectedFamily } from './core/tree/atoms'; import { collapsedFamily, isSelectedFamily, selectedIdsFamily } from './core/tree/atoms';
import type { TreeNode } from './core/tree/common'; import type { TreeNode } from './core/tree/common';
import type { TreeHandle, TreeProps } from './core/tree/Tree'; import type { TreeHandle, TreeProps } from './core/tree/Tree';
import { Tree } from './core/tree/Tree'; import { Tree } from './core/tree/Tree';
@@ -164,8 +164,10 @@ function Sidebar({ className }: { className?: string }) {
if (n == null) return; if (n == null) return;
const activeId = jotaiStore.get(activeIdAtom); const activeId = jotaiStore.get(activeIdAtom);
if (activeId == null) return; if (activeId == null) return;
const selectedIds = jotaiStore.get(selectedIdsFamily(treeId));
if (selectedIds.length > 0) return;
n.selectItem(activeId); n.selectItem(activeId);
}, []); }, [treeId]);
// Ensure active id is always selected when it changes // Ensure active id is always selected when it changes
useEffect(() => { useEffect(() => {