mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
feat(tab-group): add search to the split pane landing (#40635)
A search box finds agents and files; / moves into it from the list. The list keeps the default agent, Terminal, Browser, Markdown and Mobile emulator.
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
import { useRef } from 'react'
|
||||
import {
|
||||
FilePlus,
|
||||
Globe,
|
||||
History,
|
||||
Search,
|
||||
Smartphone,
|
||||
TerminalSquare,
|
||||
type LucideIcon
|
||||
} from 'lucide-react'
|
||||
import { useRef, useState } from 'react'
|
||||
import { FilePlus, Globe, Smartphone, TerminalSquare, type LucideIcon } from 'lucide-react'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { useAppStore } from '../../store'
|
||||
import { useShortcutKeyDetails, type ShortcutKeyComboDetails } from '@/hooks/useShortcutLabel'
|
||||
import { useOptionalShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import {
|
||||
ensureClientCreationActionAllowed,
|
||||
@@ -23,12 +15,19 @@ import {
|
||||
ensureSimulatorTab,
|
||||
getSimulatorTabForWorktree
|
||||
} from '@/lib/simulator/tabs/ensure-simulator-tab'
|
||||
import { SplitPaneLandingAgentRow } from './SplitPaneLandingAgentRow'
|
||||
import { useFileListWorktree } from '@/store/workspaces/selection/use-selected-worktree'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
LANDING_ROW_CLASS,
|
||||
LandingRowShortcut,
|
||||
moveLandingRowFocus
|
||||
} from './split-pane-landing-row'
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList
|
||||
} from '@/components/ui/command'
|
||||
import { LandingAgentResults, LandingDefaultAgentItem } from './split-pane-landing-agents'
|
||||
import { LandingFileResults } from './split-pane-landing-files'
|
||||
import { LandingItemShortcut, landingQueryMatches } from './split-pane-landing-item'
|
||||
|
||||
/** Fills an empty split pane so the user picks what opens there; each action creates into this group. */
|
||||
export function SplitPaneLanding({
|
||||
@@ -45,6 +44,11 @@ export function SplitPaneLanding({
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const [selected, setSelected] = useState('')
|
||||
const [agentPickerOpen, setAgentPickerOpen] = useState(false)
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const [query, setQuery] = useState('')
|
||||
const worktreePath = useFileListWorktree(worktreeId)?.path ?? null
|
||||
// Why: paired web clients without host streaming hide these, as the tab bar's + menu does.
|
||||
const [browserEnabled, emulatorEnabled] = useAppStore(
|
||||
useShallow((state) => {
|
||||
@@ -56,15 +60,10 @@ export function SplitPaneLanding({
|
||||
] as const
|
||||
})
|
||||
)
|
||||
const canReopen = useAppStore(
|
||||
(state) => (state.recentlyClosedTabKindsByWorktree[worktreeId]?.length ?? 0) > 0
|
||||
)
|
||||
const terminalShortcut = useShortcutKeyDetails('tab.newTerminal')
|
||||
const browserShortcut = useShortcutKeyDetails('tab.newBrowser')
|
||||
const markdownShortcut = useShortcutKeyDetails('tab.newMarkdown')
|
||||
const quickOpenShortcut = useShortcutKeyDetails('worktree.quickOpen')
|
||||
const emulatorShortcut = useShortcutKeyDetails('tab.newSimulator')
|
||||
const reopenShortcut = useShortcutKeyDetails('tab.reopenClosed')
|
||||
const terminalShortcut = useOptionalShortcutLabel('tab.newTerminal')
|
||||
const browserShortcut = useOptionalShortcutLabel('tab.newBrowser')
|
||||
const markdownShortcut = useOptionalShortcutLabel('tab.newMarkdown')
|
||||
const emulatorShortcut = useOptionalShortcutLabel('tab.newSimulator')
|
||||
|
||||
const openTerminal = (): void => {
|
||||
void openNewTerminalTabInWorkspace(useAppStore.getState, worktreeId, groupId).catch(
|
||||
@@ -97,7 +96,7 @@ export function SplitPaneLanding({
|
||||
)
|
||||
}
|
||||
|
||||
const rows: LandingRow[] = [
|
||||
const actions: LandingAction[] = [
|
||||
{
|
||||
id: 'terminal',
|
||||
icon: TerminalSquare,
|
||||
@@ -121,13 +120,6 @@ export function SplitPaneLanding({
|
||||
shortcut: markdownShortcut,
|
||||
onSelect: openMarkdown
|
||||
},
|
||||
{
|
||||
id: 'quick-open',
|
||||
icon: Search,
|
||||
label: t('components.tabGroup.splitPaneLanding.goToFile', 'Go to file'),
|
||||
shortcut: quickOpenShortcut,
|
||||
onSelect: () => useAppStore.getState().openModal('quick-open')
|
||||
},
|
||||
emulatorEnabled
|
||||
? {
|
||||
id: 'emulator',
|
||||
@@ -137,74 +129,151 @@ export function SplitPaneLanding({
|
||||
onSelect: openEmulator
|
||||
}
|
||||
: null
|
||||
].filter((row): row is LandingRow => row !== null)
|
||||
].filter(
|
||||
(action): action is LandingAction => action !== null && landingQueryMatches(action.label, query)
|
||||
)
|
||||
const searching = query.trim() !== ''
|
||||
|
||||
// Why: cmdk pulls focus into its input on every selection change, so the list keeps focus
|
||||
// outside the Command root and drives its selection here; / moves into the field.
|
||||
const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>): void => {
|
||||
const input = inputRef.current
|
||||
if (event.target === input) {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault()
|
||||
if (query !== '') {
|
||||
setQuery('')
|
||||
} else {
|
||||
listRef.current?.focus()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if (event.target !== listRef.current) {
|
||||
return
|
||||
}
|
||||
if (event.key === '/') {
|
||||
event.preventDefault()
|
||||
input?.focus()
|
||||
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
||||
event.preventDefault()
|
||||
setSelected(stepLandingSelection(listRef.current, selected, event.key === 'ArrowDown'))
|
||||
} else if (event.key === 'ArrowRight' && selected === 'default-agent') {
|
||||
event.preventDefault()
|
||||
setAgentPickerOpen(true)
|
||||
} else if (event.key === 'Enter') {
|
||||
event.preventDefault()
|
||||
listRef.current.querySelector<HTMLElement>('[cmdk-item][data-selected="true"]')?.click()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="absolute inset-0 overflow-auto scrollbar-sleek bg-background">
|
||||
<div className="mx-auto flex min-h-full w-full max-w-sm flex-col justify-center px-4 py-10">
|
||||
<div className="mb-3 px-2.5 text-sm text-muted-foreground">
|
||||
{t('components.tabGroup.splitPaneLanding.heading', 'Open in this pane')}
|
||||
</div>
|
||||
<div
|
||||
ref={listRef}
|
||||
className="flex flex-col gap-1"
|
||||
onKeyDown={(event) => moveLandingRowFocus(event, listRef.current)}
|
||||
tabIndex={-1}
|
||||
autoFocus={autoFocus}
|
||||
className="outline-none"
|
||||
onKeyDown={onKeyDown}
|
||||
>
|
||||
<SplitPaneLandingAgentRow
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
{rows.map((row) => (
|
||||
<LandingRowButton key={row.id} row={row} />
|
||||
))}
|
||||
{canReopen ? (
|
||||
<>
|
||||
<div className="mx-2.5 my-1.5 h-px bg-border" />
|
||||
<LandingRowButton
|
||||
row={{
|
||||
id: 'reopen',
|
||||
icon: History,
|
||||
label: t(
|
||||
'components.tabGroup.splitPaneLanding.reopenClosedTab',
|
||||
'Reopen closed tab'
|
||||
),
|
||||
shortcut: reopenShortcut,
|
||||
onSelect: () => useAppStore.getState().reopenClosedTab(worktreeId)
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
<Command
|
||||
surface="inline"
|
||||
shouldFilter={false}
|
||||
loop
|
||||
value={selected}
|
||||
onValueChange={setSelected}
|
||||
className="h-auto overflow-visible"
|
||||
>
|
||||
<CommandInput
|
||||
ref={inputRef}
|
||||
variant="framed"
|
||||
value={query}
|
||||
onValueChange={setQuery}
|
||||
placeholder={t(
|
||||
'components.tabGroup.splitPaneLanding.searchPlaceholder',
|
||||
'Open agent, terminal, or file…'
|
||||
)}
|
||||
/>
|
||||
<CommandList className="mt-2 h-72">
|
||||
<CommandEmpty>
|
||||
{t('components.tabGroup.splitPaneLanding.noMatches', 'No matches')}
|
||||
</CommandEmpty>
|
||||
{searching ? (
|
||||
<LandingAgentResults worktreeId={worktreeId} groupId={groupId} query={query} />
|
||||
) : null}
|
||||
{!searching || actions.length > 0 ? (
|
||||
<CommandGroup heading={t('components.tabGroup.splitPaneLanding.new', 'New')}>
|
||||
{searching ? null : (
|
||||
<LandingDefaultAgentItem
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
pickerOpen={agentPickerOpen}
|
||||
onPickerOpenChange={setAgentPickerOpen}
|
||||
onPickerClosed={() => listRef.current?.focus()}
|
||||
/>
|
||||
)}
|
||||
{actions.map((action) => (
|
||||
<CommandItem
|
||||
key={action.id}
|
||||
value={action.id}
|
||||
selection="palette"
|
||||
onSelect={action.onSelect}
|
||||
>
|
||||
<action.icon className="text-muted-foreground" />
|
||||
<span className="min-w-0 flex-1 truncate">{action.label}</span>
|
||||
<LandingItemShortcut label={action.shortcut} />
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
) : null}
|
||||
{worktreePath ? (
|
||||
<LandingFileResults
|
||||
worktreeId={worktreeId}
|
||||
worktreePath={worktreePath}
|
||||
query={query}
|
||||
/>
|
||||
) : null}
|
||||
</CommandList>
|
||||
</Command>
|
||||
</div>
|
||||
<div className="mt-3 flex items-center justify-between px-2 text-xs text-muted-foreground">
|
||||
<span>
|
||||
{t(
|
||||
'components.tabGroup.splitPaneLanding.keyboardHint',
|
||||
'↑↓ Enter to open · → agents · / to search'
|
||||
)}
|
||||
</span>
|
||||
{onClosePane ? (
|
||||
<Button type="button" variant="ghost" size="xs" onClick={onClosePane}>
|
||||
<span className="text-muted-foreground">
|
||||
{t('components.tabGroup.splitPaneLanding.closePane', 'Close pane')}
|
||||
</span>
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{onClosePane ? (
|
||||
<button
|
||||
type="button"
|
||||
className="mt-5 self-center rounded-md px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={onClosePane}
|
||||
>
|
||||
{t('components.tabGroup.splitPaneLanding.closePane', 'Close pane')}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type LandingRow = {
|
||||
type LandingAction = {
|
||||
id: string
|
||||
icon: LucideIcon
|
||||
label: string
|
||||
shortcut: ShortcutKeyComboDetails
|
||||
shortcut: string | null
|
||||
onSelect: () => void
|
||||
}
|
||||
|
||||
function LandingRowButton({ row }: { row: LandingRow }): React.JSX.Element {
|
||||
const Icon = row.icon
|
||||
return (
|
||||
<button type="button" data-landing-row className={LANDING_ROW_CLASS} onClick={row.onSelect}>
|
||||
<Icon className="size-4 text-muted-foreground" />
|
||||
<span className="min-w-0 flex-1 truncate text-left">{row.label}</span>
|
||||
<LandingRowShortcut shortcut={row.shortcut} />
|
||||
</button>
|
||||
function stepLandingSelection(list: HTMLElement, current: string, forward: boolean): string {
|
||||
const values = Array.from(
|
||||
list.querySelectorAll<HTMLElement>('[cmdk-item]:not([data-disabled="true"])'),
|
||||
(item) => item.dataset.value ?? ''
|
||||
)
|
||||
if (values.length === 0) {
|
||||
return current
|
||||
}
|
||||
const index = values.indexOf(current)
|
||||
const next = index === -1 ? 0 : (index + (forward ? 1 : -1) + values.length) % values.length
|
||||
return values[next] ?? current
|
||||
}
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
import { Bot, ChevronDown } from 'lucide-react'
|
||||
import { useAppStore } from '../../store'
|
||||
import { useShortcutKeyDetails } from '@/hooks/useShortcutLabel'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { getAgentCatalog } from '@/lib/agent-catalog/agent-catalog'
|
||||
import { AgentIcon } from '@/components/agent/icons/AgentIcon'
|
||||
import { focusTerminalTabSurface } from '@/lib/focus-terminal-tab-surface'
|
||||
import { getDetectionTargetIdentityForWorktree } from '@/lib/agent-session/launch/inventory/agent-detection-target-inventory'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { QuickLaunchAgentMenuItems } from '../tab-bar/QuickLaunchButton'
|
||||
import {
|
||||
readNewAgentTabDefault,
|
||||
resolveTerminalAgentTabShortcut
|
||||
} from '../terminal-agent-tab-shortcut'
|
||||
import { launchAgentTabShortcut } from '../agent-tab-shortcut-launch'
|
||||
import { LANDING_ROW_CLASS, LandingRowShortcut } from './split-pane-landing-row'
|
||||
|
||||
/** The default agent as one row; the chevron opens the + menu's agent list for any other. */
|
||||
export function SplitPaneLandingAgentRow({
|
||||
worktreeId,
|
||||
groupId,
|
||||
autoFocus
|
||||
}: {
|
||||
worktreeId: string
|
||||
groupId: string
|
||||
autoFocus: boolean
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const defaultAgent = useAppStore((state) => readNewAgentTabDefault(state, worktreeId))
|
||||
const shortcut = useShortcutKeyDetails('tab.newAgent')
|
||||
const label = defaultAgent
|
||||
? (getAgentCatalog().find((entry) => entry.id === defaultAgent)?.label ?? defaultAgent)
|
||||
: t('components.tabGroup.splitPaneLanding.newAgent', 'New Agent')
|
||||
|
||||
const launchDefault = (): void => {
|
||||
const resolved = resolveTerminalAgentTabShortcut({
|
||||
activeWorktreeId: worktreeId,
|
||||
keybindings: useAppStore.getState().keybindings,
|
||||
matchShortcut: (actionId) => actionId === 'tab.newAgent'
|
||||
})
|
||||
const detectionTarget = getDetectionTargetIdentityForWorktree(
|
||||
useAppStore.getState(),
|
||||
worktreeId
|
||||
)
|
||||
// Why: same cancellation as the keyboard shortcut, plus the pane must still be waiting.
|
||||
launchAgentTabShortcut(worktreeId, resolved, () => {
|
||||
const latest = useAppStore.getState()
|
||||
return (
|
||||
latest.activeWorktreeId === worktreeId &&
|
||||
getDetectionTargetIdentityForWorktree(latest, worktreeId) === detectionTarget &&
|
||||
groupStillEmpty(worktreeId, groupId)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
// Why: a stretched button keeps the row one click target while the chevron stays its own button.
|
||||
<div
|
||||
className={cn(
|
||||
LANDING_ROW_CLASS,
|
||||
'relative has-[[data-landing-row]:focus-visible]:bg-accent has-[[data-landing-row]:focus-visible]:text-accent-foreground'
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
data-landing-row
|
||||
aria-label={label}
|
||||
className="absolute inset-0 rounded-md focus-visible:outline-none"
|
||||
onClick={launchDefault}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
<span className="pointer-events-none flex text-muted-foreground">
|
||||
{defaultAgent ? <AgentIcon agent={defaultAgent} size={16} /> : <Bot className="size-4" />}
|
||||
</span>
|
||||
<span className="pointer-events-none min-w-0 truncate">{label}</span>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('components.tabGroup.splitPaneLanding.chooseAgent', 'Choose agent')}
|
||||
className="relative -ml-1.5 flex size-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-foreground/10 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-foreground/10 data-[state=open]:text-foreground"
|
||||
>
|
||||
<ChevronDown className="size-3.5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" sideOffset={6} className="w-64">
|
||||
<QuickLaunchAgentMenuItems
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
onFocusTerminal={focusTerminalTabSurface}
|
||||
/>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<span className="pointer-events-none ml-auto flex">
|
||||
<LandingRowShortcut shortcut={shortcut} />
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function groupStillEmpty(worktreeId: string, groupId: string): boolean {
|
||||
const group = (useAppStore.getState().groupsByWorktree[worktreeId] ?? []).find(
|
||||
(candidate) => candidate.id === groupId
|
||||
)
|
||||
return group !== undefined && group.tabOrder.length === 0
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import { Bot, ChevronDown } from 'lucide-react'
|
||||
import { useAppStore } from '../../store'
|
||||
import { useOptionalShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { getAgentCatalog } from '@/lib/agent-catalog/agent-catalog'
|
||||
import { AgentIcon } from '@/components/agent/icons/AgentIcon'
|
||||
import { focusTerminalTabSurface } from '@/lib/focus-terminal-tab-surface'
|
||||
import { getDetectionTargetIdentityForWorktree } from '@/lib/agent-session/launch/inventory/agent-detection-target-inventory'
|
||||
import { useAgentDetectionTargetForWorktree } from '@/hooks/useAgentDetectionTarget'
|
||||
import { CommandGroup, CommandItem } from '@/components/ui/command'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { useNewTabAgentMenuRows } from '../tab-bar/use-new-tab-agent-menu-rows'
|
||||
import { QuickLaunchAgentMenuItems, useTabAgentMenuLaunch } from '../tab-bar/QuickLaunchButton'
|
||||
import { rowId, rowLabel } from '../tab-bar/tab-agent-row-presentation'
|
||||
import {
|
||||
readNewAgentTabDefault,
|
||||
resolveTerminalAgentTabShortcut
|
||||
} from '../terminal-agent-tab-shortcut'
|
||||
import { launchAgentTabShortcut } from '../agent-tab-shortcut-launch'
|
||||
import { LandingItemShortcut, landingQueryMatches } from './split-pane-landing-item'
|
||||
|
||||
/** The default agent, launched exactly as the New Agent shortcut would launch it; the chevron
|
||||
* opens the + menu's agent list for any other. */
|
||||
export function LandingDefaultAgentItem({
|
||||
worktreeId,
|
||||
groupId,
|
||||
pickerOpen,
|
||||
onPickerOpenChange,
|
||||
onPickerClosed
|
||||
}: {
|
||||
worktreeId: string
|
||||
groupId: string
|
||||
pickerOpen: boolean
|
||||
onPickerOpenChange: (open: boolean) => void
|
||||
/** Hands focus back to the list instead of Radix's trigger restore. */
|
||||
onPickerClosed: () => void
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const defaultAgent = useAppStore((state) => readNewAgentTabDefault(state, worktreeId))
|
||||
const shortcut = useOptionalShortcutLabel('tab.newAgent')
|
||||
const agentLabel = defaultAgent
|
||||
? (getAgentCatalog().find((entry) => entry.id === defaultAgent)?.label ?? defaultAgent)
|
||||
: null
|
||||
const label = agentLabel
|
||||
? t('components.tabGroup.splitPaneLanding.newNamedAgent', 'New {{agent}} agent', {
|
||||
agent: agentLabel
|
||||
})
|
||||
: t('components.tabGroup.splitPaneLanding.newAgent', 'New Agent')
|
||||
|
||||
const launchDefault = (): void => {
|
||||
const resolved = resolveTerminalAgentTabShortcut({
|
||||
activeWorktreeId: worktreeId,
|
||||
keybindings: useAppStore.getState().keybindings,
|
||||
matchShortcut: (actionId) => actionId === 'tab.newAgent'
|
||||
})
|
||||
const detectionTarget = getDetectionTargetIdentityForWorktree(
|
||||
useAppStore.getState(),
|
||||
worktreeId
|
||||
)
|
||||
// Why: same cancellation as the keyboard shortcut, plus the pane must still be waiting.
|
||||
launchAgentTabShortcut(worktreeId, resolved, () => {
|
||||
const latest = useAppStore.getState()
|
||||
return (
|
||||
latest.activeWorktreeId === worktreeId &&
|
||||
getDetectionTargetIdentityForWorktree(latest, worktreeId) === detectionTarget &&
|
||||
groupStillEmpty(worktreeId, groupId)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<CommandItem value="default-agent" selection="palette" onSelect={launchDefault}>
|
||||
{defaultAgent ? <AgentIcon agent={defaultAgent} size={16} /> : <Bot />}
|
||||
<span className="min-w-0 truncate">{label}</span>
|
||||
<DropdownMenu open={pickerOpen} onOpenChange={onPickerOpenChange}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('components.tabGroup.splitPaneLanding.chooseAgent', 'Choose agent')}
|
||||
className="-ml-1 flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-foreground/10 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-foreground/10 data-[state=open]:text-foreground"
|
||||
// Why: the row's own click launches the default agent; the chevron only opens the list.
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<ChevronDown className="size-3.5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="start"
|
||||
sideOffset={6}
|
||||
className="w-64"
|
||||
// Why: the portaled menu still bubbles through React to the row, whose click launches the default.
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault()
|
||||
onPickerClosed()
|
||||
}}
|
||||
>
|
||||
<QuickLaunchAgentMenuItems
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
onFocusTerminal={focusTerminalTabSurface}
|
||||
/>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<span className="flex-1" />
|
||||
<LandingItemShortcut label={shortcut} />
|
||||
</CommandItem>
|
||||
)
|
||||
}
|
||||
|
||||
/** Every launchable agent matching the query, from the same rows as the + menu. */
|
||||
export function LandingAgentResults({
|
||||
worktreeId,
|
||||
groupId,
|
||||
query
|
||||
}: {
|
||||
worktreeId: string
|
||||
groupId: string
|
||||
query: string
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const detectionTarget = useAgentDetectionTargetForWorktree(worktreeId)
|
||||
const model = useNewTabAgentMenuRows(worktreeId, true, detectionTarget)
|
||||
const runLaunch = useTabAgentMenuLaunch({
|
||||
worktreeId,
|
||||
groupId,
|
||||
onFocusTerminal: focusTerminalTabSurface
|
||||
})
|
||||
if (model.state !== 'settled') {
|
||||
return null
|
||||
}
|
||||
const matches = model.rows.filter(
|
||||
(row) => row.kind !== 'chat-unavailable' && landingQueryMatches(rowLabel(row, t), query)
|
||||
)
|
||||
if (matches.length === 0) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<CommandGroup heading={t('components.tabGroup.splitPaneLanding.agents', 'Agents')}>
|
||||
{matches.map((row) => (
|
||||
<CommandItem
|
||||
key={rowId(row)}
|
||||
value={`agent:${rowId(row)}`}
|
||||
selection="palette"
|
||||
onSelect={() => runLaunch(row)}
|
||||
>
|
||||
<AgentIcon agent={row.agent} size={16} />
|
||||
<span className="min-w-0 flex-1 truncate">{rowLabel(row, t)}</span>
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
)
|
||||
}
|
||||
|
||||
function groupStillEmpty(worktreeId: string, groupId: string): boolean {
|
||||
const group = (useAppStore.getState().groupsByWorktree[worktreeId] ?? []).find(
|
||||
(candidate) => candidate.id === groupId
|
||||
)
|
||||
return group !== undefined && group.tabOrder.length === 0
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { useDeferredValue, useMemo } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { FileTypeIcon } from '@/components/FileTypeIcon'
|
||||
import { splitTrailingSegment } from '@/components/file-path-cursor-tooltip'
|
||||
import { CommandGroup, CommandItem } from '@/components/ui/command'
|
||||
import { useQuickOpenHistory } from '@/lib/quick-open-file-history'
|
||||
import { useRuntimeFileListForWorktree } from '@/components/quick-open-file-list'
|
||||
import { parseQuickOpenQueryTarget } from '../../../../shared/quick-open/quick-open-query-target'
|
||||
import { openQuickOpenFile } from '../quick-open-file-navigation'
|
||||
import { rankQuickOpenFilesWithHistory } from '../quick-open-history-ranking'
|
||||
|
||||
const MAX_FILE_RESULTS = 8
|
||||
|
||||
/** Go to File's search, shown only once the user types; recent files stay in Go to File. */
|
||||
export function LandingFileResults({
|
||||
worktreeId,
|
||||
worktreePath,
|
||||
query
|
||||
}: {
|
||||
worktreeId: string
|
||||
worktreePath: string
|
||||
query: string
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const deferredQuery = useDeferredValue(query.trim())
|
||||
const target = useMemo(() => parseQuickOpenQueryTarget(deferredQuery), [deferredQuery])
|
||||
const history = useQuickOpenHistory(worktreeId, worktreePath)
|
||||
const { files } = useRuntimeFileListForWorktree({
|
||||
enabled: deferredQuery !== '',
|
||||
worktreeId,
|
||||
query: target.pathQuery,
|
||||
recentPaths: history
|
||||
})
|
||||
const matches = useMemo(
|
||||
() =>
|
||||
deferredQuery === ''
|
||||
? []
|
||||
: rankQuickOpenFilesWithHistory(target.pathQuery, files, history).slice(
|
||||
0,
|
||||
MAX_FILE_RESULTS
|
||||
),
|
||||
[deferredQuery, target.pathQuery, files, history]
|
||||
)
|
||||
if (matches.length === 0) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<CommandGroup heading={t('components.tabGroup.splitPaneLanding.files', 'Files')}>
|
||||
{matches.map(({ path }) => {
|
||||
const { directory, filename } = splitTrailingSegment(path)
|
||||
return (
|
||||
<CommandItem
|
||||
key={path}
|
||||
value={`file:${path}`}
|
||||
selection="palette"
|
||||
onSelect={() => {
|
||||
void openQuickOpenFile(path, worktreeId, worktreePath, target, deferredQuery).catch(
|
||||
(error: unknown) =>
|
||||
toast.error(error instanceof Error ? error.message : String(error))
|
||||
)
|
||||
}}
|
||||
>
|
||||
<FileTypeIcon filePath={path} className="size-4 text-muted-foreground" />
|
||||
<span className="min-w-0 max-w-full shrink-0 truncate">{filename}</span>
|
||||
{directory ? (
|
||||
<span className="ml-auto min-w-0 truncate text-xs text-muted-foreground">
|
||||
{directory}
|
||||
</span>
|
||||
) : null}
|
||||
</CommandItem>
|
||||
)
|
||||
})}
|
||||
</CommandGroup>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/** Same look as DropdownMenuShortcut, so the landing reads like the + menu it mirrors. */
|
||||
export function LandingItemShortcut({ label }: { label: string | null }): React.JSX.Element | null {
|
||||
if (!label) {
|
||||
return null
|
||||
}
|
||||
return <span className="ml-auto text-xs tracking-widest text-muted-foreground">{label}</span>
|
||||
}
|
||||
|
||||
export function landingQueryMatches(label: string, query: string): boolean {
|
||||
const needle = query.trim().toLowerCase()
|
||||
return needle === '' || label.toLowerCase().includes(needle)
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import type { ShortcutKeyComboDetails } from '@/hooks/useShortcutLabel'
|
||||
import { ShortcutKeyCombo } from '../ShortcutKeyCombo'
|
||||
|
||||
export const LANDING_ROW_CLASS =
|
||||
'flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-sm text-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground focus-visible:outline-none'
|
||||
|
||||
export function LandingRowShortcut({
|
||||
shortcut
|
||||
}: {
|
||||
shortcut: ShortcutKeyComboDetails
|
||||
}): React.JSX.Element | null {
|
||||
if (shortcut.keys.length === 0) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<ShortcutKeyCombo
|
||||
keys={shortcut.keys}
|
||||
doubleTap={shortcut.doubleTap}
|
||||
className="shrink-0"
|
||||
separatorClassName="mx-0.5 text-2xs text-muted-foreground"
|
||||
keyCapClassName="min-w-5 px-1 py-0 text-2xs leading-5 shadow-none"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Up/Down walk the rows like a menu; Tab still reaches the agent picker and Close pane. */
|
||||
export function moveLandingRowFocus(
|
||||
event: React.KeyboardEvent<HTMLElement>,
|
||||
list: HTMLElement | null
|
||||
): void {
|
||||
if (
|
||||
!list ||
|
||||
(event.key !== 'ArrowDown' && event.key !== 'ArrowUp') ||
|
||||
// Why: the agent menu is portaled but still bubbles through React; leave its keys alone.
|
||||
!(event.target instanceof Node && list.contains(event.target))
|
||||
) {
|
||||
return
|
||||
}
|
||||
const rows = Array.from(list.querySelectorAll<HTMLElement>('[data-landing-row]'))
|
||||
const active = document.activeElement
|
||||
const current = active instanceof HTMLElement ? rows.indexOf(active) : -1
|
||||
const step = event.key === 'ArrowDown' ? 1 : -1
|
||||
const next = rows[(current + step + rows.length) % rows.length]
|
||||
if (next) {
|
||||
event.preventDefault()
|
||||
next.focus()
|
||||
}
|
||||
}
|
||||
@@ -21809,15 +21809,19 @@
|
||||
},
|
||||
"tabGroup": {
|
||||
"splitPaneLanding": {
|
||||
"agents": "Agents",
|
||||
"browser": "Browser",
|
||||
"chooseAgent": "Choose agent",
|
||||
"closePane": "Close pane",
|
||||
"goToFile": "Go to file",
|
||||
"heading": "Open in this pane",
|
||||
"files": "Files",
|
||||
"keyboardHint": "↑↓ Enter to open · → agents · / to search",
|
||||
"markdown": "Markdown",
|
||||
"mobileEmulator": "Mobile emulator",
|
||||
"new": "New",
|
||||
"newAgent": "New Agent",
|
||||
"reopenClosedTab": "Reopen closed tab",
|
||||
"newNamedAgent": "New {{agent}} agent",
|
||||
"noMatches": "No matches",
|
||||
"searchPlaceholder": "Open agent, terminal, or file…",
|
||||
"terminal": "Terminal"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user