fix: the consistency of the go-to-anything interaction (#28857)

This commit is contained in:
非法操作
2025-11-28 14:29:15 +08:00
committed by GitHub
parent 1fc2255219
commit c51ab6ec37

View File

@@ -187,6 +187,19 @@ const GotoAnything: FC<Props> = ({
}, {} as { [key: string]: SearchResult[] }), }, {} as { [key: string]: SearchResult[] }),
[searchResults]) [searchResults])
useEffect(() => {
if (isCommandsMode)
return
if (!searchResults.length)
return
const currentValueExists = searchResults.some(result => `${result.type}-${result.id}` === cmdVal)
if (!currentValueExists)
setCmdVal(`${searchResults[0].type}-${searchResults[0].id}`)
}, [isCommandsMode, searchResults, cmdVal])
const emptyResult = useMemo(() => { const emptyResult = useMemo(() => {
if (searchResults.length || !searchQuery.trim() || isLoading || isCommandsMode) if (searchResults.length || !searchQuery.trim() || isLoading || isCommandsMode)
return null return null
@@ -386,7 +399,7 @@ const GotoAnything: FC<Props> = ({
<Command.Item <Command.Item
key={`${result.type}-${result.id}`} key={`${result.type}-${result.id}`}
value={`${result.type}-${result.id}`} value={`${result.type}-${result.id}`}
className='flex cursor-pointer items-center gap-3 rounded-md p-3 will-change-[background-color] aria-[selected=true]:bg-state-base-hover data-[selected=true]:bg-state-base-hover' className='flex cursor-pointer items-center gap-3 rounded-md p-3 will-change-[background-color] hover:bg-state-base-hover aria-[selected=true]:bg-state-base-hover-alt data-[selected=true]:bg-state-base-hover-alt'
onSelect={() => handleNavigate(result)} onSelect={() => handleNavigate(result)}
> >
{result.icon} {result.icon}