diff --git a/src/renderer/src/components/QuickOpen.tsx b/src/renderer/src/components/QuickOpen.tsx index 5dbeb3796..c0884653b 100644 --- a/src/renderer/src/components/QuickOpen.tsx +++ b/src/renderer/src/components/QuickOpen.tsx @@ -1,5 +1,5 @@ /* oxlint-disable max-lines */ -import React, { useCallback, useEffect, useMemo, useState } from 'react' +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { File } from 'lucide-react' import { useAppStore } from '@/store' import { detectLanguage } from '@/lib/language-detect' @@ -63,6 +63,7 @@ export default function QuickOpen(): React.JSX.Element | null { const [files, setFiles] = useState([]) const [loading, setLoading] = useState(false) const [loadError, setLoadError] = useState(null) + const listRef = useRef(null) // Find active worktree path const worktreePath = useMemo(() => { @@ -138,6 +139,13 @@ export default function QuickOpen(): React.JSX.Element | null { return results.slice(0, 50) }, [files, query]) + // Why: when the query changes the first result becomes selected, but cmdk + // doesn't reset the list's scrollTop. Without this, a previously scrolled + // list leaves the new top result clipped behind the input border. + useEffect(() => { + listRef.current?.scrollTo(0, 0) + }, [query, visible]) + const handleSelect = useCallback( (relativePath: string) => { if (!activeWorktreeId || !worktreePath) { @@ -178,16 +186,10 @@ export default function QuickOpen(): React.JSX.Element | null { title="Go to file" description="Search for a file to open" > - - + + {loading ? ( -
- Loading files... -
+
Loading files...
) : loadError ? (
{loadError}
) : filtered.length === 0 ? (