diff --git a/src/renderer/src/components/tab-group/SplitPaneLanding.tsx b/src/renderer/src/components/tab-group/SplitPaneLanding.tsx index b8675b5aefe..e4f3678719e 100644 --- a/src/renderer/src/components/tab-group/SplitPaneLanding.tsx +++ b/src/renderer/src/components/tab-group/SplitPaneLanding.tsx @@ -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(null) + const [selected, setSelected] = useState('') + const [agentPickerOpen, setAgentPickerOpen] = useState(false) + const inputRef = useRef(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): 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('[cmdk-item][data-selected="true"]')?.click() + } + } return (
-
- {t('components.tabGroup.splitPaneLanding.heading', 'Open in this pane')} -
moveLandingRowFocus(event, listRef.current)} + tabIndex={-1} + autoFocus={autoFocus} + className="outline-none" + onKeyDown={onKeyDown} > - - {rows.map((row) => ( - - ))} - {canReopen ? ( - <> -
- useAppStore.getState().reopenClosedTab(worktreeId) - }} - /> - + + + + + {t('components.tabGroup.splitPaneLanding.noMatches', 'No matches')} + + {searching ? ( + + ) : null} + {!searching || actions.length > 0 ? ( + + {searching ? null : ( + listRef.current?.focus()} + /> + )} + {actions.map((action) => ( + + + {action.label} + + + ))} + + ) : null} + {worktreePath ? ( + + ) : null} + + +
+
+ + {t( + 'components.tabGroup.splitPaneLanding.keyboardHint', + '↑↓ Enter to open · → agents · / to search' + )} + + {onClosePane ? ( + ) : null}
- {onClosePane ? ( - - ) : null}
) } -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 ( - +function stepLandingSelection(list: HTMLElement, current: string, forward: boolean): string { + const values = Array.from( + list.querySelectorAll('[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 } diff --git a/src/renderer/src/components/tab-group/SplitPaneLandingAgentRow.tsx b/src/renderer/src/components/tab-group/SplitPaneLandingAgentRow.tsx deleted file mode 100644 index 5f3be9f4759..00000000000 --- a/src/renderer/src/components/tab-group/SplitPaneLandingAgentRow.tsx +++ /dev/null @@ -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. -
- - - - - - - - - -
- ) -} - -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 -} diff --git a/src/renderer/src/components/tab-group/split-pane-landing-agents.tsx b/src/renderer/src/components/tab-group/split-pane-landing-agents.tsx new file mode 100644 index 00000000000..1d9bdbaf7ec --- /dev/null +++ b/src/renderer/src/components/tab-group/split-pane-landing-agents.tsx @@ -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 ( + + {defaultAgent ? : } + {label} + + + + + event.stopPropagation()} + onCloseAutoFocus={(event) => { + event.preventDefault() + onPickerClosed() + }} + > + + + + + + + ) +} + +/** 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 ( + + {matches.map((row) => ( + runLaunch(row)} + > + + {rowLabel(row, t)} + + ))} + + ) +} + +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 +} diff --git a/src/renderer/src/components/tab-group/split-pane-landing-files.tsx b/src/renderer/src/components/tab-group/split-pane-landing-files.tsx new file mode 100644 index 00000000000..2a1f1afeb74 --- /dev/null +++ b/src/renderer/src/components/tab-group/split-pane-landing-files.tsx @@ -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 ( + + {matches.map(({ path }) => { + const { directory, filename } = splitTrailingSegment(path) + return ( + { + void openQuickOpenFile(path, worktreeId, worktreePath, target, deferredQuery).catch( + (error: unknown) => + toast.error(error instanceof Error ? error.message : String(error)) + ) + }} + > + + {filename} + {directory ? ( + + {directory} + + ) : null} + + ) + })} + + ) +} diff --git a/src/renderer/src/components/tab-group/split-pane-landing-item.tsx b/src/renderer/src/components/tab-group/split-pane-landing-item.tsx new file mode 100644 index 00000000000..003fd1c4c3a --- /dev/null +++ b/src/renderer/src/components/tab-group/split-pane-landing-item.tsx @@ -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 {label} +} + +export function landingQueryMatches(label: string, query: string): boolean { + const needle = query.trim().toLowerCase() + return needle === '' || label.toLowerCase().includes(needle) +} diff --git a/src/renderer/src/components/tab-group/split-pane-landing-row.tsx b/src/renderer/src/components/tab-group/split-pane-landing-row.tsx deleted file mode 100644 index ab31be8e758..00000000000 --- a/src/renderer/src/components/tab-group/split-pane-landing-row.tsx +++ /dev/null @@ -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 ( - - ) -} - -/** Up/Down walk the rows like a menu; Tab still reaches the agent picker and Close pane. */ -export function moveLandingRowFocus( - event: React.KeyboardEvent, - 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('[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() - } -} diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 41cb9645fc1..45e08a0481e 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -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" } },