From 756a7fa7b954023cf1e5314d10f84dbd513617b2 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sat, 18 Apr 2026 17:51:21 -0700 Subject: [PATCH] fix(quick-open): reset scroll and add padding so top result isn't clipped (#808) The Cmd+P dialog's first result sometimes appeared flush against (or behind) the input's bottom border. cmdk moves selection to the first result on query change but never resets the list's scrollTop, and the list had no padding buffer between the input border and the first item. - reset scrollTop on query/visible change (mirrors WorktreeJumpPalette) - add p-2 padding so the selection highlight never touches the border --- src/renderer/src/components/QuickOpen.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 ? (