Open History to see the last commit
1import { isElectron } from "~/env";
2
3export type SettingsPath =
4 | "/settings/general"
5 | "/settings/appearance"
6 | "/settings/keybindings"
7 | "/settings/providers"
8 | "/settings/integrations"
9 | "/settings/source-control"
10 | "/settings/connections"
11 | "/settings/archived";
12
13export interface SettingsSearchItem {
14 readonly id: string;
15 readonly title: string;
16 readonly to: SettingsPath;
17 readonly targetId?: string;
18 // Its row only renders in the desktop app, so a browser result would land on
19 // an anchor that isn't there.
20 readonly desktopOnly?: boolean;
21}
22
23/**
24 * Section labels in sidebar order. The sidebar nav and the search-result
25 * subtitles both render from this record, so each label exists once.
26 */
27export const SETTINGS_SECTION_LABELS: Readonly<Record<SettingsPath, string>> = {
28 "/settings/general": "General",
29 "/settings/appearance": "Appearance",
30 "/settings/keybindings": "Keybindings",
31 "/settings/providers": "Providers",
32 "/settings/integrations": "Integrations",
33 "/settings/source-control": "Source Control",
34 "/settings/connections": "Connections",
35 "/settings/archived": "Archive",
36};
37
38/**
39 * Every searchable setting, in result order. This catalog is the single
40 * source of truth for anchor ids and visible titles: panels render both via
41 * `searchableSetting`, so a retitle (or, later, a translation pass) happens
42 * here once instead of separately in the panel and the index.
43 */
44export const SETTINGS_SEARCH_ITEMS = [
45 {
46 id: "color-scheme",
47 title: "Color scheme",
48 to: "/settings/appearance",
49 // The scheme tiles sit at the top of the Appearance section.
50 targetId: "appearance",
51 },
52 {
53 id: "theme",
54 title: "Themes",
55 to: "/settings/appearance",
56 // Theme cards live directly under the scheme tiles; the section is the
57 // stable scroll destination for both.
58 targetId: "appearance",
59 },
60 {
61 // Prefixed because the slider control already owns the `appearance-contrast` id.
62 id: "setting-appearance-contrast",
63 title: "Contrast",
64 to: "/settings/appearance",
65 },
66 {
67 // Prefixed because the slider control already owns the `glass-opacity` id.
68 id: "setting-glass-opacity",
69 title: "Glass opacity",
70 to: "/settings/appearance",
71 },
72 {
73 id: "environment-identification",
74 title: "Environment identification",
75 to: "/settings/appearance",
76 // The setting is stage-dependent, so its parent section is the stable destination.
77 targetId: "appearance",
78 },
79 {
80 id: "interface-font",
81 title: "Interface font",
82 to: "/settings/appearance",
83 },
84 {
85 id: "prompt-font",
86 title: "Prompt font",
87 to: "/settings/appearance",
88 },
89 {
90 id: "code-font",
91 title: "Code font",
92 to: "/settings/appearance",
93 },
94 {
95 id: "terminal-font",
96 title: "Terminal font",
97 to: "/settings/appearance",
98 },
99 {
100 id: "font-smoothing",
101 title: "Font smoothing",
102 to: "/settings/appearance",
103 },
104 {
105 id: "word-wrap",
106 title: "Word wrap",
107 to: "/settings/appearance",
108 },
109 {
110 id: "project-grouping",
111 title: "Project grouping",
112 to: "/settings/general",
113 },
114 {
115 id: "auto-settle-inactive-threads",
116 title: "Auto-settle inactive threads",
117 to: "/settings/general",
118 },
119 {
120 id: "auto-settle-merged-threads",
121 title: "Auto-settle merged threads",
122 to: "/settings/general",
123 },
124 {
125 id: "time-format",
126 title: "Time format",
127 to: "/settings/general",
128 },
129 {
130 id: "hide-whitespace-changes",
131 title: "Hide whitespace changes",
132 to: "/settings/general",
133 },
134 {
135 id: "provider-update-checks",
136 title: "Provider update checks",
137 to: "/settings/general",
138 },
139 {
140 id: "new-threads",
141 title: "New threads",
142 to: "/settings/general",
143 },
144 {
145 id: "start-from-origin",
146 title: "Start from origin",
147 to: "/settings/general",
148 targetId: "new-threads",
149 },
150 {
151 id: "add-project-starts-in",
152 title: "Add project starts in",
153 to: "/settings/general",
154 },
155 {
156 id: "archive-confirmation",
157 title: "Archive confirmation",
158 to: "/settings/general",
159 },
160 {
161 id: "delete-confirmation",
162 title: "Delete confirmation",
163 to: "/settings/general",
164 },
165 {
166 id: "quit-confirmation",
167 title: "Hold to quit",
168 to: "/settings/general",
169 desktopOnly: true,
170 },
171 {
172 id: "text-generation-model",
173 title: "Text generation model",
174 to: "/settings/general",
175 },
176 {
177 id: "diagnostics",
178 title: "Diagnostics",
179 to: "/settings/general",
180 },
181 {
182 id: "legacy-plan-mode",
183 title: "Plan mode (legacy)",
184 to: "/settings/general",
185 },
186 {
187 id: "legacy-token-streaming",
188 title: "Stream token by token (legacy)",
189 to: "/settings/general",
190 },
191 {
192 id: "legacy-sidebar",
193 title: "Sidebar (legacy)",
194 to: "/settings/general",
195 },
196 {
197 id: "keybindings",
198 title: "Keybindings",
199 to: "/settings/keybindings",
200 },
201 {
202 id: "providers",
203 title: "Providers",
204 to: "/settings/providers",
205 },
206 {
207 id: "agent-browser-access",
208 title: "Agent browser access",
209 to: "/settings/integrations",
210 targetId: "browser",
211 },
212 {
213 id: "browser-default-viewport",
214 title: "Default browser viewport",
215 to: "/settings/integrations",
216 targetId: "browser",
217 },
218 {
219 id: "browser-default-zoom",
220 title: "Default browser zoom",
221 to: "/settings/integrations",
222 targetId: "browser",
223 },
224 {
225 id: "browser-default-appearance",
226 title: "Default browser appearance",
227 to: "/settings/integrations",
228 targetId: "browser",
229 },
230 {
231 id: "browser-auto-show-floating-preview",
232 title: "Auto-show floating preview",
233 to: "/settings/integrations",
234 targetId: "browser",
235 },
236 {
237 id: "source-control",
238 title: "Source control",
239 to: "/settings/source-control",
240 },
241 {
242 id: "remote-environments",
243 title: "Remote environments",
244 to: "/settings/connections",
245 },
246 {
247 id: "archive",
248 title: "Archived threads",
249 to: "/settings/archived",
250 },
251] as const satisfies ReadonlyArray<SettingsSearchItem>;
252
253export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
254
255const SEARCH_ITEMS_BY_ID = Object.fromEntries(
256 SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item]),
257) as Readonly<Record<SettingsSearchItemId, SettingsSearchItem>>;
258
259/**
260 * `id` and `title` props for the element a search item anchors to. Panels
261 * spread (or pick from) this instead of restating the strings, so the catalog
262 * and the rendered settings cannot drift apart.
263 */
264export function searchableSetting(id: SettingsSearchItemId): {
265 readonly id: string;
266 readonly title: string;
267} {
268 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID[id];
269 return { id: anchorId, title };
270}
271
272function normalizeSearchText(value: string): string {
273 return value
274 .normalize("NFKD")
275 .replace(/[\u0300-\u036f]/g, "")
276 .toLocaleLowerCase()
277 .replace(/\s+/g, " ")
278 .trim();
279}
280
281export function searchSettings(
282 query: string,
283 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
284): ReadonlyArray<SettingsSearchItem> {
285 const normalizedQuery = normalizeSearchText(query);
286 if (normalizedQuery.length === 0) return [];
287
288 return items.filter(
289 (item) =>
290 (isElectron || item.desktopOnly !== true) &&
291 normalizeSearchText(item.title).includes(normalizedQuery),
292 );
293}