// The "?" cheat sheet: every keyboard shortcut for the page you are on, plus the ones that work everywhere. import { useEffect, useRef } from 'react'; import { useApp } from '../context/AppContext.js'; import { themeVars } from './reader/readerThemes.js'; const GLOBAL = [ ['⌘K / Ctrl K', 'Search and go to a passage'], ['?', 'Show this list'], ['Esc', 'Close whatever is open'], ]; const BY_PAGE = { reader: [ ['← →', 'Previous / next chapter'], ['/', 'Search this chapter or the whole Bible'], ['G', 'Pick a book and chapter'], ['B', 'Bookmark the selected verse'], ['C', 'Compare translations'], ['H', 'Your highlights'], [',', 'Reading settings'], ['F', 'Hide or show the controls'], ], study: [ ['← →', 'Previous / next chunk'], ], }; export default function ShortcutsHelp({ onClose }) { const { readerTheme, currentPage } = useApp(); const closeRef = useRef(null); useEffect(() => { const from = document.activeElement; closeRef.current?.focus(); const onKey = (e) => { if (e.key === 'Escape' || e.key === '?') { e.preventDefault(); e.stopPropagation(); onClose(); } }; document.addEventListener('keydown', onKey, true); return () => { document.removeEventListener('keydown', onKey, true); if (from instanceof HTMLElement && document.contains(from)) from.focus({ preventScroll: true }); }; }, [onClose]); const page = BY_PAGE[currentPage] ?? []; const section = (title, rows) => (