mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(sessions): focus picker search after the tab shortcut on touch devices
This commit is contained in:
1 parent
abcecd1c0c
commit
afc95039a8
2 files changed
+31
-1
No files matched your search
@@ -540,6 +540,29 @@ describe('SessionPickerDialog', () => {
|
||||
await waitFor(() => expect(screen.getByPlaceholderText('Search projects...')).toHaveFocus())
|
||||
})
|
||||
|
||||
it('focuses the projects search input after the switch shortcut on a coarse pointer device', async () => {
|
||||
stubMatchMedia(false)
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
await user.click(screen.getByPlaceholderText('Search sessions...'))
|
||||
await user.keyboard('{Control>}s{/Control}')
|
||||
|
||||
await waitFor(() => expect(screen.getByPlaceholderText('Search projects...')).toHaveFocus())
|
||||
})
|
||||
|
||||
it('does not focus the projects search input when switching tabs by pointer on a coarse pointer device', async () => {
|
||||
stubMatchMedia(false)
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'Projects' }))
|
||||
|
||||
expect(await screen.findByPlaceholderText('Search projects...')).not.toHaveFocus()
|
||||
})
|
||||
|
||||
it('lists repos in the projects tab and opens the cursor repo on Enter', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
const { onSelectRepo } = renderPicker()
|
||||
|
||||
@@ -705,6 +705,7 @@ export function SessionPickerDialog({
|
||||
}: SessionPickerDialogProps) {
|
||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||
const projectSearchInputRef = useRef<HTMLInputElement>(null)
|
||||
const focusSearchAfterSwitchRef = useRef(false)
|
||||
const hasFinePointer = useMediaQuery(FINE_POINTER_MEDIA_QUERY)
|
||||
const { preferences } = useSettings()
|
||||
const switchHint = useMemo(
|
||||
@@ -727,14 +728,20 @@ export function SessionPickerDialog({
|
||||
}
|
||||
|
||||
const toggleTab = useCallback(() => {
|
||||
focusSearchAfterSwitchRef.current = true
|
||||
setTab((current) => (current === 'sessions' ? 'projects' : 'sessions'))
|
||||
}, [])
|
||||
|
||||
useShortcutActions({ switchPickerTab: open ? toggleTab : undefined })
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !hasFinePointer) return
|
||||
if (!open) {
|
||||
focusSearchAfterSwitchRef.current = false
|
||||
return
|
||||
}
|
||||
if (!hasFinePointer && !focusSearchAfterSwitchRef.current) return
|
||||
const frame = requestAnimationFrame(() => {
|
||||
focusSearchAfterSwitchRef.current = false
|
||||
if (tab === 'projects') projectSearchInputRef.current?.focus()
|
||||
else searchInputRef.current?.focus()
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user