From 8ea62f4b231e6cae8dbdad8e522216a669e5c268 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 17 Sep 2025 19:38:22 -0300 Subject: [PATCH 1/5] feat: add 'search' funcionalities, both for file names and file contents --- src/components/Shakespeare/FileTree.tsx | 118 +++++++++++++++++++++++- 1 file changed, 113 insertions(+), 5 deletions(-) diff --git a/src/components/Shakespeare/FileTree.tsx b/src/components/Shakespeare/FileTree.tsx index 0cb506ee..5621c5e1 100644 --- a/src/components/Shakespeare/FileTree.tsx +++ b/src/components/Shakespeare/FileTree.tsx @@ -2,9 +2,11 @@ import { useState, useEffect, useCallback } from 'react'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useFS } from '@/hooks/useFS'; import { useGitStatus } from '@/hooks/useGitStatus'; -import { ChevronRight, ChevronDown, File, Folder } from 'lucide-react'; +import { ChevronRight, ChevronDown, File, Folder, Search, FileText } from 'lucide-react'; import { cn } from '@/lib/utils'; import { createGitignoreFilter, normalizePathForGitignore } from '@/lib/gitignore'; +import { Input } from '@/components/ui/input'; +import { Button } from '@/components/ui/button'; interface FileTreeProps { projectId: string; @@ -22,11 +24,15 @@ interface FileNode { export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProps) { const [tree, setTree] = useState([]); + const [filteredTree, setFilteredTree] = useState([]); const [isLoading, setIsLoading] = useState(true); const [gitignoreFilter, setGitignoreFilter] = useState<{ isIgnored: (path: string) => boolean; shouldShow: (path: string) => boolean; } | null>(null); + const [searchTerm, setSearchTerm] = useState(''); + const [searchInContent, setSearchInContent] = useState(false); + const [isSearching, setIsSearching] = useState(false); const { fs } = useFS(); const projectsManager = useProjectsManager(); const { data: gitStatus } = useGitStatus(projectId); @@ -127,6 +133,7 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp const structure = await buildFileTree(projectId, ''); setTree(structure); + setFilteredTree(structure); } catch (_error) { console.error('Failed to load file tree:', _error); } finally { @@ -151,7 +158,9 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp }); }; + // Update both the original tree and filtered tree setTree(prev => toggleNode(prev)); + setFilteredTree(prev => toggleNode(prev)); }; const handleFileClick = (filePath: string, type: 'file' | 'directory') => { @@ -162,6 +171,71 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp } }; + // Search functions + const searchInFiles = useCallback(async (nodes: FileNode[], term: string): Promise => { + if (!term.trim()) return nodes; + + const results: FileNode[] = []; + const searchTermLower = term.toLowerCase(); + + for (const node of nodes) { + if (node.type === 'file') { + const fileNameMatch = node.name.toLowerCase().includes(searchTermLower); + + if (fileNameMatch) { + results.push(node); + } else if (searchInContent) { + try { + const content = await projectsManager.readFile(projectId, node.path); + const contentMatch = content.toLowerCase().includes(searchTermLower); + + if (contentMatch) { + results.push(node); + } + } catch (error) { + // Skip files that can't be read + console.warn(`Could not read file ${node.path}:`, error); + } + } + } else if (node.type === 'directory' && node.children) { + const childResults = await searchInFiles(node.children, term); + if (childResults.length > 0) { + // Create a filtered directory node with matching children + results.push({ + ...node, + children: childResults, + isOpen: true, // Auto-expand directories with matches + }); + } + } + } + + return results; + }, [projectsManager, projectId, searchInContent]); + + // Perform search when search term or searchInContent changes + useEffect(() => { + const performSearch = async () => { + if (!searchTerm.trim()) { + setFilteredTree(tree); + return; + } + + setIsSearching(true); + try { + const results = await searchInFiles(tree, searchTerm); + setFilteredTree(results); + } catch (error) { + console.error('Search failed:', error); + setFilteredTree([]); + } finally { + setIsSearching(false); + } + }; + + performSearch(); + }, [searchTerm, searchInContent, tree, searchInFiles]); + const renderNode = (node: FileNode, depth: number = 0) => { const isSelected = selectedFile === node.path; @@ -232,12 +306,46 @@ export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProp return (
- {tree.length === 0 ? ( -
- No files found + {/* Search Section */} +
+
+ + setSearchTerm(e.target.value)} + className="pl-8" + /> +
+
+ + {isSearching && ( +
Searching...
+ )} +
+
+ + {/* File Tree */} + {isSearching ? ( +
+ {[...Array(3)].map((_, i) => ( +
+ ))} +
+ ) : filteredTree.length === 0 ? ( +
+ {searchTerm ? 'No files found matching your search' : 'No files found'}
) : ( - tree.map(node => renderNode(node)) + filteredTree.map(node => renderNode(node)) )}
); From fec198e7b35f593905b97bb2672aab5f22347828 Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 18 Sep 2025 17:13:20 +0700 Subject: [PATCH 2/5] css fix: use flex so that cells can't overlap --- src/components/Shakespeare/ChatPane.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index b24cb465..31cb4fdf 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -526,7 +526,7 @@ export const ChatPane = forwardRef(({
{/* Chat Input Container */} -
+