mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(tab-group): offer quick commands from pane actions when the strip hides them
When a narrow strip folds the quick-command button away, the pane actions menu now carries the same Quick Commands submenu the terminal and chat menus use, so running or adding a command still works from the strip. The narrow-strip e2e no longer sleeps or casts: it retries the first Tab until focus lands in the strip, and a new test checks the menu offers quick commands only when the button is hidden.
This commit is contained in:
@@ -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<HTMLElement | null>
|
||||
}
|
||||
|
||||
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 (
|
||||
<Tooltip>
|
||||
<DropdownMenu modal={false} open={open} onOpenChange={setOpen}>
|
||||
<TooltipTrigger asChild>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('auto.components.tab.group.TabGroupPanel.9acaf92093', 'Pane Actions')}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
}}
|
||||
className="my-auto flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-accent/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
|
||||
>
|
||||
<Ellipsis className="size-4" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
</TooltipTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
side="bottom"
|
||||
sideOffset={4}
|
||||
onCloseAutoFocus={(event) => {
|
||||
if (!isFocused) {
|
||||
event.preventDefault()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DropdownMenuItem variant="destructive" onSelect={() => onCloseGroup()}>
|
||||
<X className="size-4" />
|
||||
{t('auto.components.tab.group.TabGroupPanel.closePaneColumn', 'Close split pane')}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{t('auto.components.tab.group.TabGroupPanel.9acaf92093', 'Pane Actions')}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<>
|
||||
<Tooltip>
|
||||
<DropdownMenu modal={false} open={open} onOpenChange={handleOpenChange}>
|
||||
<TooltipTrigger asChild>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('auto.components.tab.group.TabGroupPanel.9acaf92093', 'Pane Actions')}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
}}
|
||||
className="my-auto flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-accent/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
|
||||
>
|
||||
<Ellipsis className="size-4" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
</TooltipTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
side="bottom"
|
||||
sideOffset={4}
|
||||
onCloseAutoFocus={(event) => {
|
||||
if (!isFocused) {
|
||||
event.preventDefault()
|
||||
}
|
||||
}}
|
||||
>
|
||||
{quickCommands.menu ? (
|
||||
<>
|
||||
{quickCommands.menu}
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
) : null}
|
||||
<DropdownMenuItem variant="destructive" onSelect={() => onCloseGroup()}>
|
||||
<X className="size-4" />
|
||||
{t('auto.components.tab.group.TabGroupPanel.closePaneColumn', 'Close split pane')}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{t('auto.components.tab.group.TabGroupPanel.9acaf92093', 'Pane Actions')}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
{quickCommands.dialog}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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<HTMLDivElement>(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. */}
|
||||
<div className="contents @max-[163px]/tab-strip:hidden">
|
||||
<div ref={quickCommandsSlotRef} className="contents @max-[163px]/tab-strip:hidden">
|
||||
<TabBarQuickCommandsButton
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
@@ -327,6 +328,9 @@ export default function TabGroupPanel({
|
||||
<TabGroupPaneActionsMenu
|
||||
isFocused={isFocused}
|
||||
onCloseGroup={commands.closeGroup}
|
||||
worktreeId={worktreeId}
|
||||
groupId={groupId}
|
||||
quickCommandsSlotRef={quickCommandsSlotRef}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -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<FocusedControl> {
|
||||
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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user