diff --git a/src/renderer/src/components/tab-group/TabGroupPaneActionsMenu.tsx b/src/renderer/src/components/tab-group/TabGroupPaneActionsMenu.tsx index ad5ea6a60b4..92584b99375 100644 --- a/src/renderer/src/components/tab-group/TabGroupPaneActionsMenu.tsx +++ b/src/renderer/src/components/tab-group/TabGroupPaneActionsMenu.tsx @@ -1,66 +1,100 @@ -import { useState } from 'react' +import { useState, type RefObject } from 'react' import { Ellipsis, X } from 'lucide-react' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, + DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { useTranslate } from '@/i18n/use-translate' +import { useNativeChatQuickCommandsMenu } from '../native-chat/pane/actions/use-native-chat-quick-commands-menu' type TabGroupPaneActionsMenuProps = { isFocused: boolean onCloseGroup: () => void + worktreeId: string + groupId: string + /** The strip's quick-command slot; when a narrow strip hides it, this menu offers quick commands instead. */ + quickCommandsSlotRef: RefObject +} + +function isSlotHidden(slot: HTMLElement | null): boolean { + return Boolean(slot && slot.childElementCount > 0 && getComputedStyle(slot).display === 'none') } export function TabGroupPaneActionsMenu({ isFocused, - onCloseGroup + onCloseGroup, + worktreeId, + groupId, + quickCommandsSlotRef }: TabGroupPaneActionsMenuProps): React.JSX.Element { const t = useTranslate() const [open, setOpen] = useState(false) + const [offerQuickCommands, setOfferQuickCommands] = useState(false) + const quickCommands = useNativeChatQuickCommandsMenu( + offerQuickCommands ? { worktreeId, groupId } : undefined, + () => setOpen(false) + ) + const handleOpenChange = (next: boolean): void => { + // Why: the menu renders in a portal, so check the strip's container-query result when it opens. + if (next) { + setOfferQuickCommands(isSlotHidden(quickCommandsSlotRef.current)) + } + setOpen(next) + } // Why: the strip stays mounted when focus or the workspace moves away; close so it can't act on a stale group. if (!isFocused && open) { setOpen(false) } return ( - - - - - - - - { - if (!isFocused) { - event.preventDefault() - } - }} - > - onCloseGroup()}> - - {t('auto.components.tab.group.TabGroupPanel.closePaneColumn', 'Close split pane')} - - - - - {t('auto.components.tab.group.TabGroupPanel.9acaf92093', 'Pane Actions')} - - + <> + + + + + + + + { + if (!isFocused) { + event.preventDefault() + } + }} + > + {quickCommands.menu ? ( + <> + {quickCommands.menu} + + + ) : null} + onCloseGroup()}> + + {t('auto.components.tab.group.TabGroupPanel.closePaneColumn', 'Close split pane')} + + + + + {t('auto.components.tab.group.TabGroupPanel.9acaf92093', 'Pane Actions')} + + + {quickCommands.dialog} + ) } diff --git a/src/renderer/src/components/tab-group/TabGroupPanel.tsx b/src/renderer/src/components/tab-group/TabGroupPanel.tsx index 04331d311fa..fca41ebd10e 100644 --- a/src/renderer/src/components/tab-group/TabGroupPanel.tsx +++ b/src/renderer/src/components/tab-group/TabGroupPanel.tsx @@ -1,4 +1,4 @@ -import { Suspense, useCallback, useMemo } from 'react' +import { Suspense, useCallback, useMemo, useRef } from 'react' import { lazyWithRetry as lazy } from '@/app-shell/startup/lazy-with-retry' import { useDroppable } from '@dnd-kit/core' import { useAppStore } from '../../store/index' @@ -77,6 +77,7 @@ export default function TabGroupPanel({ const sidebarOpen = useAppStore((state) => state.sidebarOpen) const reserveRightTitlebarSpace = reserveClosedExplorerToggleSpace && !rightSidebarOpen const model = useTabGroupWorkspaceModel({ groupId, worktreeId }) + const quickCommandsSlotRef = useRef(null) const { activeTab, agentSessionItems, @@ -315,7 +316,7 @@ export default function TabGroupPanel({ > {/* Why: drop an action whole (and from Tab order) once it can't fit beside the tab floor and "+", never leave a clipped focus target. 163 = 40 tab + 36 "+" + 8 padding + 47 widest collapsed quick-command trigger + 2 gap + 28 pane actions + 2 sub-pixel slack; 114 = 40 + 36 + 8 + 28 + 2. */} -
+
) : null} diff --git a/tests/e2e/narrow-tab-group-drag-handle.spec.ts b/tests/e2e/narrow-tab-group-drag-handle.spec.ts index 6fa4b356ffd..0123ae9b862 100644 --- a/tests/e2e/narrow-tab-group-drag-handle.spec.ts +++ b/tests/e2e/narrow-tab-group-drag-handle.spec.ts @@ -76,50 +76,54 @@ async function draggableTabRun(page: Page, groupId: string): Promise<{ width: nu }, groupId) } -/** Tab through a strip from its first tab; report each strip control (not a tab's own close button) that took focus and whether all of it is visible. */ +type FocusedControl = { label: string; fullyVisible: boolean } | 'in-tab' | null + +/** The strip control holding focus (null outside the strip, 'in-tab' for a tab's own controls) and whether all of it is visible. */ +async function focusedStripControl(page: Page, groupId: string): Promise { + return page.evaluate((id) => { + const el = document.activeElement + const stripEl = document.querySelector(`[data-tab-group-strip-id="${id}"]`) + if (!(el instanceof HTMLElement) || !stripEl?.contains(el)) { + return null + } + if (el.closest('[data-tab-id]')) { + return 'in-tab' + } + const r = el.getBoundingClientRect() + const y = r.top + r.height / 2 + const shows = (x: number): boolean => { + const hit = document.elementFromPoint(x, y) + return Boolean(hit && (hit === el || el.contains(hit))) + } + return { + label: el.getAttribute('aria-label') ?? el.textContent?.trim() ?? el.tagName, + fullyVisible: r.width > 0 && shows(r.left + 1) && shows(r.right - 1) + } + }, groupId) +} + +/** Tab through a strip from its first tab; report each strip control (not a tab's own close button) that took focus. */ async function tabThroughStrip( page: Page, groupId: string ): Promise<{ label: string; fullyVisible: boolean }[]> { - const strip = page.locator(`[data-tab-group-strip-id="${groupId}"]`) - const tab = strip.locator('[data-tab-id]').first() - // Why: focusing a group can hand focus to its terminal a beat later; walk only from a tab that still holds focus. + const tab = page.locator(`[data-tab-group-strip-id="${groupId}"] [data-tab-id]`).first() + // Why: focusing a group can hand focus to its terminal a beat later, so retry until Tab from the tab lands in the strip. await expect .poll(async () => { await tab.focus() - await page.waitForTimeout(100) - return tab.evaluate((el) => el === document.activeElement) + await page.keyboard.press('Tab') + return focusedStripControl(page, groupId) }) - .toBe(true) + .not.toBeNull() + let focused = await focusedStripControl(page, groupId) const visited: { label: string; fullyVisible: boolean }[] = [] - for (let i = 0; i < 8; i++) { - await page.keyboard.press('Tab') - const focused = await page.evaluate((id) => { - const el = document.activeElement as HTMLElement | null - const stripEl = document.querySelector(`[data-tab-group-strip-id="${id}"]`) - if (!el || !stripEl?.contains(el)) { - return null - } - if (el.closest('[data-tab-id]')) { - return 'in-tab' - } - const r = el.getBoundingClientRect() - const y = r.top + r.height / 2 - const shows = (x: number): boolean => { - const hit = document.elementFromPoint(x, y) - return Boolean(hit && (hit === el || el.contains(hit))) - } - return { - label: el.getAttribute('aria-label') ?? el.textContent?.trim() ?? el.tagName, - fullyVisible: r.width > 0 && shows(r.left + 1) && shows(r.right - 1) - } - }, groupId) - if (!focused) { - break - } + for (let i = 0; i < 8 && focused; i++) { if (focused !== 'in-tab') { visited.push(focused) } + await page.keyboard.press('Tab') + focused = await focusedStripControl(page, groupId) } return visited } @@ -188,3 +192,34 @@ test('a narrow tab group keeps a grabbable tab and can be dragged into another g await expect(leftStrip.locator('[data-tab-id]')).toHaveCount(2) await expect(rightStrip.locator('[data-tab-id]')).toHaveCount(0) }) + +test('a strip too narrow for quick commands offers them in the pane actions menu', async ({ + orcaPage +}) => { + await orcaPage.setViewportSize({ width: 1280, height: 800 }) + await waitForSessionReady(orcaPage) + const worktreeId = await waitForActiveWorktree(orcaPage) + await ensureTerminalVisible(orcaPage) + + const layout = await buildThreeColumns(orcaPage, worktreeId) + const rightStrip = orcaPage.locator(`[data-tab-group-strip-id="${layout.rightGroupId}"]`) + const paneActions = rightStrip.getByRole('button', { name: 'Pane Actions' }) + const quickCommandsItem = orcaPage.getByRole('menuitem', { name: 'Quick Commands' }) + + // Normal width shows the quick-command button, so the menu does not repeat it. + await expect(rightStrip.getByRole('button', { name: 'Add quick command' })).toBeVisible() + await paneActions.click() + await expect(orcaPage.getByRole('menuitem', { name: 'Close split pane' })).toBeVisible() + await expect(quickCommandsItem).toHaveCount(0) + await orcaPage.keyboard.press('Escape') + + // Root 80/20, then 25/75 inside it: about 134px, too narrow for quick commands but not for the menu. + await orcaPage.evaluate((id) => { + const state = window.__store?.getState() + state?.setTabGroupSplitRatio(id, '', 0.8) + state?.setTabGroupSplitRatio(id, 'second', 0.25) + }, worktreeId) + await expect(rightStrip.getByRole('button', { name: 'Add quick command' })).toBeHidden() + await paneActions.click() + await expect(quickCommandsItem).toBeVisible() +})