Files
opencode-manager/frontend/src/hooks/useMediaQuery.ts
T
Chris Scott 7102715068 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.
2026-10-02 10:45:20 -04:00

28 lines
832 B
TypeScript

import { useEffect, useState } from 'react'
export const DESKTOP_MEDIA_QUERY = '(min-width: 640px)'
export const FINE_POINTER_MEDIA_QUERY = '(hover: hover) and (pointer: fine)'
export function useMediaQuery(query: string): boolean {
const [matches, setMatches] = useState<boolean>(() => {
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
return false
}
return window.matchMedia(query).matches
})
useEffect(() => {
if (typeof window.matchMedia !== 'function') {
return
}
const mediaQuery = window.matchMedia(query)
setMatches(mediaQuery.matches)
const update = () => setMatches(mediaQuery.matches)
mediaQuery.addEventListener('change', update)
return () => mediaQuery.removeEventListener('change', update)
}, [query])
return matches
}