mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(ui): app-wide keyboard shortcuts with TUI keybind import
This commit is contained in:
1 parent
b18e4f13b3
commit
b06de60f6b
38 files changed
+2467
-440
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { describe, expect, it, vi, afterEach } from 'vitest'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ReactNode } from 'react'
|
||||
import { MemoryRouter, useLocation } from 'react-router-dom'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
import { ToolSidePanel } from './ToolSidePanel'
|
||||
import { useToolPanel } from '@/hooks/useToolPanel'
|
||||
|
||||
@@ -43,6 +44,7 @@ function Harness({ docked }: { docked: boolean }) {
|
||||
const panel = useToolPanel(docked)
|
||||
return (
|
||||
<>
|
||||
<textarea data-prompt-input aria-label="prompt" />
|
||||
{docked ? (
|
||||
<ToolSidePanel
|
||||
panel={panel}
|
||||
@@ -83,6 +85,10 @@ function HomeHarness() {
|
||||
)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
Reflect.deleteProperty(window, 'matchMedia')
|
||||
})
|
||||
|
||||
describe('ToolSidePanel', () => {
|
||||
it('shows the tool name in a tooltip when hovering a rail icon', async () => {
|
||||
const user = userEvent.setup()
|
||||
@@ -229,4 +235,19 @@ describe('ToolSidePanel', () => {
|
||||
await waitFor(() => expect(search().get('dialog')).toBe('sourceControl'))
|
||||
expect(search().has('panel')).toBe(false)
|
||||
})
|
||||
|
||||
it('moves focus to the chat prompt when the docked panel closes on desktop', async () => {
|
||||
stubMatchMedia(true)
|
||||
const user = userEvent.setup()
|
||||
renderAt('')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Files' }))
|
||||
const closeButton = await screen.findByRole('button', { name: 'Close panel' })
|
||||
closeButton.focus()
|
||||
|
||||
await user.click(closeButton)
|
||||
|
||||
await waitFor(() => expect(search().has('panel')).toBe(false))
|
||||
expect(screen.getByLabelText('prompt')).toHaveFocus()
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { X } from 'lucide-react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { FileBrowser } from '@/components/file-browser/FileBrowser'
|
||||
@@ -19,6 +20,7 @@ import { buildToolItems, type MoreDrawerItem } from '@/components/navigation/mor
|
||||
import { isPanelTool, type ToolPanelState, type PanelTool } from '@/hooks/useToolPanel'
|
||||
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { restoreOverlayFocus } from '@/lib/overlayFocus'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface ToolSidePanelProps {
|
||||
@@ -90,6 +92,19 @@ export function ToolSidePanel({
|
||||
const { activeTool, toggleTool, closePanel } = panel
|
||||
const location = useLocation()
|
||||
const openNavItem = useOpenNavItem()
|
||||
const railRef = useRef<HTMLElement>(null)
|
||||
const previousActiveToolRef = useRef(activeTool)
|
||||
|
||||
useEffect(() => {
|
||||
const previousTool = previousActiveToolRef.current
|
||||
previousActiveToolRef.current = activeTool
|
||||
if (previousTool === null || activeTool !== null) return
|
||||
const active = document.activeElement
|
||||
if (active === null || active === document.body || railRef.current?.contains(active)) {
|
||||
restoreOverlayFocus(null)
|
||||
}
|
||||
}, [activeTool])
|
||||
|
||||
const panelTools: Array<{ item: MoreDrawerItem; tool: PanelTool }> = []
|
||||
const actionItems: MoreDrawerItem[] = []
|
||||
for (const item of buildToolItems(location.pathname)) {
|
||||
@@ -182,7 +197,7 @@ export function ToolSidePanel({
|
||||
) : null}
|
||||
|
||||
<TooltipProvider>
|
||||
<nav aria-label="Tools" className="flex w-11 shrink-0 flex-col items-center gap-1 overflow-y-auto border-l border-border bg-background py-2">
|
||||
<nav ref={railRef} aria-label="Tools" className="flex w-11 shrink-0 flex-col items-center gap-1 overflow-y-auto border-l border-border bg-background py-2">
|
||||
{panelTools.map(({ item, tool }) => (
|
||||
<RailButton key={item.key} item={item} active={tool === activeTool} onClick={() => toggleTool(tool)} />
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user