feat: keyboard shortcuts for email navigation

'/' focuses the search bar from anywhere (Layout-level listener).
j/k move focus up/down the email list in FolderView and SearchResults;
e archives the focused email, # trashes it. All shortcuts are ignored
while an input/textarea/select has focus, so typing is never hijacked.

A small hint footer in the bottom-right reminds users of the shortcuts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
cesnimda
2026-06-30 21:55:36 +02:00
parent c11d747919
commit 7710d49c77
6 changed files with 78 additions and 3 deletions
+20 -1
View File
@@ -1,5 +1,5 @@
import { Link, Outlet, useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import { useEffect, useState, useCallback } from 'react';
import { useEffect, useState, useCallback, useRef } from 'react';
import { AuthApi, SyncApi, AnalyticsApi } from '../api/client.js';
import Logo from './Logo.jsx';
import DevBanner from './DevBanner.jsx';
@@ -129,9 +129,23 @@ export default function Layout() {
const loc = useLocation();
const navigate = useNavigate();
const searchInputRef = useRef(null);
useEffect(() => { AuthApi.me().then(setUser).catch(() => {}); }, []);
// "/" focuses the search bar from anywhere, unless already typing in a field.
useEffect(() => {
const handler = (e) => {
if (e.key !== '/') return;
const tag = document.activeElement?.tagName;
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
e.preventDefault();
searchInputRef.current?.focus();
};
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, []);
useEffect(() => {
AnalyticsApi.sidebarCounts().then(setCounts).catch(() => {});
}, []);
@@ -227,6 +241,7 @@ export default function Layout() {
</nav>
<form className="search-form" onSubmit={submitSearch}>
<input
ref={searchInputRef}
className="search-input"
type="search"
placeholder="Search… (from:, is:unread, has:attachment)"
@@ -322,6 +337,10 @@ export default function Layout() {
<Outlet />
</main>
</div>
<div className="kbd-hint">
<kbd>/</kbd> search · <kbd>j</kbd>/<kbd>k</kbd> navigate · <kbd>e</kbd> archive · <kbd>#</kbd> trash
</div>
</div>
);
}