CI / Build & Quality Checks (push) Skipped
CI / Secret scan (gitleaks) (push) Skipped
CI / Playwright smoke (e2e) (push) Skipped
CI / Build & Quality Checks (pull_request) Successful in 3m44s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 16s
CI / Playwright smoke (e2e) (pull_request) Failing after 23m12s
A search box at the top of the settings sidebar (Ctrl/Cmd+F while settings are open). Results replace the page list while typing, showing the page and section; picking one (or Enter for the top result) opens that page, scrolls to the setting and briefly outlines it. Esc clears. The index is built from the settings source itself (SettingTile titles and descriptions, section headers), loaded as raw text in a lazy chunk on first search, so options added later are found without a hand-kept list. Desktop-only options only show in the desktop app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
130 lines
4.3 KiB
TypeScript
130 lines
4.3 KiB
TypeScript
import React, { useEffect, useRef, useState } from 'react';
|
|
import { Box, Icon, IconButton, Icons, Input, MenuItem, Text, config } from 'folds';
|
|
import { SettingsPages } from '../pages';
|
|
import { searchSettings, SettingsEntry } from './settingsIndex';
|
|
import { loadSettingsIndex } from './loadSettingsIndex';
|
|
import { isTauri } from '../../../hooks/useTauri';
|
|
|
|
type SettingsSearchProps = {
|
|
pageNames: Map<SettingsPages, string>;
|
|
/** Whether a query is active (the page list is hidden meanwhile). */
|
|
onActiveChange: (active: boolean) => void;
|
|
onPick: (entry: SettingsEntry) => void;
|
|
};
|
|
|
|
/**
|
|
* [Gitea #463] Search box at the top of the settings sidebar. Ctrl/Cmd+F
|
|
* focuses it while settings are open; Esc clears it.
|
|
*/
|
|
export function SettingsSearch({ pageNames, onActiveChange, onPick }: SettingsSearchProps) {
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
const [query, setQuery] = useState('');
|
|
const [entries, setEntries] = useState<SettingsEntry[]>();
|
|
const active = query.trim().length > 0;
|
|
|
|
useEffect(() => onActiveChange(active), [active, onActiveChange]);
|
|
|
|
const ensureIndex = () => {
|
|
if (!entries) loadSettingsIndex().then(setEntries, () => setEntries([]));
|
|
};
|
|
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => {
|
|
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'f') {
|
|
// Capture phase + stop: settings is on top, so this beats the app's
|
|
// own Ctrl/Cmd+F (message search) underneath.
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
inputRef.current?.focus();
|
|
inputRef.current?.select();
|
|
}
|
|
};
|
|
window.addEventListener('keydown', onKey, true);
|
|
return () => window.removeEventListener('keydown', onKey, true);
|
|
}, []);
|
|
|
|
// Only desktop-app options in the desktop app; only pages that exist here.
|
|
const results = entries
|
|
? searchSettings(entries, query, { desktop: isTauri() }).filter((e) => pageNames.has(e.page))
|
|
: [];
|
|
|
|
return (
|
|
<Box direction="Column" gap="200" style={{ padding: `0 ${config.space.S200}` }}>
|
|
<Input
|
|
ref={inputRef}
|
|
size="400"
|
|
variant="Background"
|
|
radii="400"
|
|
placeholder="Search settings"
|
|
aria-label="Search settings"
|
|
value={query}
|
|
onFocus={ensureIndex}
|
|
onChange={(e) => {
|
|
ensureIndex();
|
|
setQuery(e.currentTarget.value);
|
|
}}
|
|
onKeyDown={(e) => {
|
|
if (e.key === 'Escape' && query) {
|
|
e.stopPropagation();
|
|
setQuery('');
|
|
}
|
|
if (e.key === 'Enter' && results[0]) {
|
|
onPick(results[0]);
|
|
setQuery('');
|
|
}
|
|
}}
|
|
before={<Icon size="100" src={Icons.Search} />}
|
|
after={
|
|
query ? (
|
|
<IconButton
|
|
size="300"
|
|
radii="300"
|
|
variant="Background"
|
|
aria-label="Clear search"
|
|
onClick={() => setQuery('')}
|
|
>
|
|
<Icon size="50" src={Icons.Cross} />
|
|
</IconButton>
|
|
) : undefined
|
|
}
|
|
/>
|
|
{active && (
|
|
<Box direction="Column" role="list" aria-label="Matching settings">
|
|
{entries === undefined && (
|
|
<Text size="T200" priority="300" style={{ padding: config.space.S200 }}>
|
|
Searching…
|
|
</Text>
|
|
)}
|
|
{entries !== undefined && results.length === 0 && (
|
|
<Text size="T200" priority="300" style={{ padding: config.space.S200 }}>
|
|
No settings match “{query.trim()}”.
|
|
</Text>
|
|
)}
|
|
{results.map((r) => (
|
|
<MenuItem
|
|
key={`${r.page}-${r.title}`}
|
|
role="listitem"
|
|
variant="Background"
|
|
radii="400"
|
|
onClick={() => {
|
|
onPick(r);
|
|
setQuery('');
|
|
}}
|
|
>
|
|
<Box direction="Column" style={{ padding: `${config.space.S100} 0`, minWidth: 0 }}>
|
|
<Text size="T300" truncate>
|
|
{r.title}
|
|
</Text>
|
|
<Text size="T200" priority="300" truncate>
|
|
{pageNames.get(r.page)}
|
|
{r.section && r.section !== r.title ? ` · ${r.section}` : ''}
|
|
</Text>
|
|
</Box>
|
|
</MenuItem>
|
|
))}
|
|
</Box>
|
|
)}
|
|
</Box>
|
|
);
|
|
}
|