From ee8aec479b8f418f6f479e852757bb90c1456f7e Mon Sep 17 00:00:00 2001 From: Gagancreates Date: Thu, 7 May 2026 23:47:18 +0530 Subject: [PATCH] fix: clear folder highlight when a note is opened --- .../renderer/src/components/sidebar-content.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/x/apps/renderer/src/components/sidebar-content.tsx b/apps/x/apps/renderer/src/components/sidebar-content.tsx index 2944908f..ec3f1239 100644 --- a/apps/x/apps/renderer/src/components/sidebar-content.tsx +++ b/apps/x/apps/renderer/src/components/sidebar-content.tsx @@ -1143,21 +1143,25 @@ function KnowledgeSection({ } }, [selectedPath, expandedPaths, tree]) - // Intercept file/folder clicks to track the active folder context + // Folder clicks highlight the folder; file clicks clear folder highlight const handleSelect = React.useCallback((path: string, kind: "file" | "dir") => { if (kind === 'dir') { setSelectedFolderPath(path) } else { - const parts = path.split('/') - setSelectedFolderPath(parts.length > 1 ? parts.slice(0, -1).join('/') : 'knowledge') + setSelectedFolderPath(null) } onSelectFile(path, kind) }, [onSelectFile]) - // Resolve the parent path for new items based on current context + // Resolve the parent path for new items: explicit folder > open file's parent > root const deriveParent = React.useCallback((): string => { - return selectedFolderPath ?? 'knowledge' - }, [selectedFolderPath]) + if (selectedFolderPath) return selectedFolderPath + if (selectedPath) { + const parts = selectedPath.split('/') + if (parts.length > 1) return parts.slice(0, -1).join('/') + } + return 'knowledge' + }, [selectedFolderPath, selectedPath]) // Wrap actions to inject context-aware parent and capture rename target const wrappedActions = React.useMemo(() => ({