diff --git a/src/components/FileTree.tsx b/src/components/FileTree.tsx index d010d3edc..2eecccfc7 100644 --- a/src/components/FileTree.tsx +++ b/src/components/FileTree.tsx @@ -154,6 +154,8 @@ const FileTreeItem = ({ onCreateFolder, newTreeEntry, level = 0, + treeSelection, + setTreeSelection, }: { parentDir: FileEntry | undefined project?: IndexLoaderData['project'] @@ -170,12 +172,15 @@ const FileTreeItem = ({ onCreateFolder: (name: string) => void newTreeEntry: TreeEntry level?: number + treeSelection: FileEntry | undefined + setTreeSelection: Dispatch> }) => { const { send: fileSend, context: fileContext } = useFileContext() const { onFileOpen, onFileClose } = useLspContext() const navigate = useNavigate() const [isConfirmingDelete, setIsConfirmingDelete] = useState(false) const isCurrentFile = fileOrDir.path === currentFile?.path + const isFileOrDirHighlighted = treeSelection?.path === fileOrDir?.path const itemRef = useRef(null) // Since every file or directory gets its own FileTreeItem, we can do this. @@ -242,6 +247,8 @@ const FileTreeItem = ({ } async function handleClick() { + setTreeSelection(fileOrDir) + if (fileOrDir.children !== null) return // Don't open directories if (fileOrDir.name?.endsWith(FILE_EXT) === false && project?.path) { @@ -263,6 +270,7 @@ const FileTreeItem = ({ // Open kcl files navigate(`${PATHS.FILE}/${encodeURIComponent(fileOrDir.path)}`) } + onNavigateToFile?.() } @@ -274,7 +282,7 @@ const FileTreeItem = ({
  • { @@ -402,6 +408,8 @@ const FileTreeItem = ({ onNavigateToFile={onNavigateToFile} level={level + 1} key={level + '-' + child.path} + treeSelection={treeSelection} + setTreeSelection={setTreeSelection} /> ) )} @@ -626,6 +634,10 @@ export const FileTreeInner = ({ FileEntry | undefined >(undefined) + const [treeSelection, setTreeSelection] = useState( + loaderData.file + ) + const onNavigateToFile_ = () => { // Reset modeling state when navigating to a new file onNavigateToFile?.() @@ -678,6 +690,7 @@ export const FileTreeInner = ({ // We're at the root, can't select anything further if (!target) return + setTreeSelection(target) setLastDirectoryClicked(target) fileSend({ type: 'Set selected directory', @@ -722,6 +735,8 @@ export const FileTreeInner = ({ onClickDirectory={onClickDirectory} onNavigateToFile={onNavigateToFile_} key={fileOrDir.path} + treeSelection={treeSelection} + setTreeSelection={setTreeSelection} /> ) )}