fix(commands): run multi-line and Enter commands, restore focus, refresh forks

- Match command arguments across newlines so a multi-line /btw or custom
  command runs instead of being sent as plain text.
- Run a typed command on plain Enter once its name is complete, while
  Enter stays a new line for regular text and Shift+Enter for commands.
- Focus the prompt when a session opens on a pointer device, and return
  focus to the previously focused element when a dialog closes, except a
  text field on touch so the keyboard stays closed.
- Invalidate the session list on session.forked so a forked session shows
  in the sidebar without waiting for the next event.
- Correct the Quick Start keyboard shortcuts.
This commit is contained in:
Chris Scott committed 2026-10-02 10:45:20 -04:00
1 parent 7e93eb4c34
commit 7102715068
10 files changed
+330 -17

No files matched your search

@@ -1,5 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { stubMatchMedia } from '@/test/test-utils'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import { useState } from 'react'
import { SideQuestionDialog } from './SideQuestionDialog'
const mocks = vi.hoisted(() => ({
@@ -22,11 +24,50 @@ const renderDialog = (props: Partial<React.ComponentProps<typeof SideQuestionDia
/>,
)
function FocusHost() {
const [open, setOpen] = useState(false)
return (
<>
<textarea aria-label="prompt" />
<button type="button" onClick={() => setOpen(true)}>open</button>
{open && (
<SideQuestionDialog
open
sessionID="ses_1"
onOpenChange={(next) => {
if (!next) setOpen(false)
}}
/>
)}
</>
)
}
describe('SideQuestionDialog', () => {
beforeEach(() => {
vi.clearAllMocks()
})
afterEach(() => {
Reflect.deleteProperty(window, 'matchMedia')
})
it('focuses its input on open and returns focus to the previous element on Escape', async () => {
stubMatchMedia(true)
render(<FocusHost />)
const prompt = screen.getByLabelText('prompt')
prompt.focus()
fireEvent.click(screen.getByText('open'))
const input = await screen.findByPlaceholderText('Ask a side question')
await waitFor(() => expect(input).toHaveFocus())
fireEvent.keyDown(input, { key: 'Escape' })
await waitFor(() => expect(prompt).toHaveFocus())
})
it('asks a non-empty initial question once on mount and renders the answer', async () => {
mocks.askSideQuestion.mockResolvedValue('**42**')