Simplify file picker to show only git files with filtering
- Remove server file search API calls - Only use git file status for file list - Filter git files by search query on client side - Add trailing / when inserting folder paths - Simpler and faster implementation - Respects gitignore (via git status)
This commit is contained in:
@@ -66,11 +66,6 @@ const FilePicker: Component<FilePickerProps> = (props) => {
|
||||
}
|
||||
|
||||
async function fetchFiles(searchQuery: string) {
|
||||
if (!props.instanceClient) {
|
||||
console.log("[FilePicker] No instance client for file search")
|
||||
return
|
||||
}
|
||||
|
||||
console.log(`[FilePicker] Fetching files for query: "${searchQuery}"`)
|
||||
setLoading(true)
|
||||
const startTime = Date.now()
|
||||
@@ -79,49 +74,12 @@ const FilePicker: Component<FilePickerProps> = (props) => {
|
||||
const gitFiles = cachedGitFiles()
|
||||
console.log(`[FilePicker] Using ${gitFiles.length} cached git files`)
|
||||
|
||||
let searchFiles: FileItem[] = []
|
||||
|
||||
if (searchQuery.trim()) {
|
||||
console.log(`[FilePicker] Searching files with query: "${searchQuery}"`)
|
||||
const searchResponse = await props.instanceClient.find.files({
|
||||
query: { query: searchQuery },
|
||||
})
|
||||
const elapsed = Date.now() - startTime
|
||||
|
||||
console.log(`[FilePicker] Search response received in ${elapsed}ms:`, searchResponse)
|
||||
|
||||
searchFiles = (searchResponse?.data || [])
|
||||
.filter((path: string) => !gitFiles.some((gf) => gf.path === path))
|
||||
.map((path: string) => ({
|
||||
path,
|
||||
isGitFile: false,
|
||||
}))
|
||||
} else {
|
||||
console.log(`[FilePicker] Empty query, fetching all files`)
|
||||
const searchResponse = await props.instanceClient.find.files({
|
||||
query: { query: "" },
|
||||
})
|
||||
const elapsed = Date.now() - startTime
|
||||
|
||||
console.log(`[FilePicker] All files response received in ${elapsed}ms:`, searchResponse)
|
||||
|
||||
searchFiles = (searchResponse?.data || [])
|
||||
.filter((path: string) => !gitFiles.some((gf) => gf.path === path))
|
||||
.map((path: string) => ({
|
||||
path,
|
||||
isGitFile: false,
|
||||
}))
|
||||
}
|
||||
|
||||
const filteredGitFiles = searchQuery.trim()
|
||||
? gitFiles.filter((f) => f.path.toLowerCase().includes(searchQuery.toLowerCase()))
|
||||
: gitFiles
|
||||
const allFiles = [...filteredGitFiles, ...searchFiles]
|
||||
|
||||
console.log(
|
||||
`[FilePicker] Showing ${allFiles.length} files (${filteredGitFiles.length} git + ${searchFiles.length} search)`,
|
||||
)
|
||||
setFiles(allFiles)
|
||||
console.log(`[FilePicker] Showing ${filteredGitFiles.length} git files`)
|
||||
setFiles(filteredGitFiles)
|
||||
setSelectedIndex(0)
|
||||
} catch (error) {
|
||||
const elapsed = Date.now() - startTime
|
||||
|
||||
@@ -328,14 +328,13 @@ export default function PromptInput(props: PromptInputProps) {
|
||||
if (pos !== null) {
|
||||
const before = currentPrompt.substring(0, pos + 1)
|
||||
const after = currentPrompt.substring(cursorPos)
|
||||
const folderPath = path.slice(0, -1)
|
||||
const newPrompt = before + folderPath + after
|
||||
const newPrompt = before + path + after
|
||||
setPrompt(newPrompt)
|
||||
setFileSearchQuery(folderPath)
|
||||
setFileSearchQuery(path)
|
||||
|
||||
setTimeout(() => {
|
||||
if (textareaRef) {
|
||||
const newCursorPos = pos + 1 + folderPath.length
|
||||
const newCursorPos = pos + 1 + path.length
|
||||
textareaRef.setSelectionRange(newCursorPos, newCursorPos)
|
||||
textareaRef.style.height = "auto"
|
||||
textareaRef.style.height = Math.min(textareaRef.scrollHeight, 200) + "px"
|
||||
|
||||
Reference in New Issue
Block a user