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: "skills-in-slash-menu",
136 title: "Show skills in slash menu",
137 to: "/settings/general",
138 },
139 {
140 id: "provider-update-checks",
141 title: "Provider update checks",
142 to: "/settings/general",
143 },
144 {
145 id: "new-threads",
146 title: "New threads",
147 to: "/settings/general",
148 },
149 {
150 id: "start-from-origin",
151 title: "Start from origin",
152 to: "/settings/general",
153 targetId: "new-threads",
154 },
155 {
156 id: "add-project-starts-in",
157 title: "Add project starts in",
158 to: "/settings/general",
159 },
160 {
161 id: "unpin-confirmation",
162 title: "Unpin confirmation",
163 to: "/settings/general",
164 },
165 {
166 id: "archive-confirmation",
167 title: "Archive confirmation",
168 to: "/settings/general",
169 },
170 {
171 id: "delete-confirmation",
172 title: "Delete confirmation",
173 to: "/settings/general",
174 },
175 {
176 id: "quit-confirmation",
177 title: "Hold to quit",
178 to: "/settings/general",
179 desktopOnly: true,
180 },
181 {
182 id: "text-generation-model",
183 title: "Text generation model",
184 to: "/settings/general",
185 },
186 {
187 id: "diagnostics",
188 title: "Diagnostics",
189 to: "/settings/general",
190 },
191 {
192 id: "legacy-plan-mode",
193 title: "Plan mode (legacy)",
194 to: "/settings/general",
195 },
196 {
197 id: "legacy-token-streaming",
198 title: "Stream token by token (legacy)",
199 to: "/settings/general",
200 },
201 {
202 id: "legacy-sidebar",
203 title: "Sidebar (legacy)",
204 to: "/settings/general",
205 },
206 {
207 id: "keybindings",
208 title: "Keybindings",
209 to: "/settings/keybindings",
210 },
211 {
212 id: "providers",
213 title: "Providers",
214 to: "/settings/providers",
215 },
216 {
217 id: "agent-browser-access",
218 title: "Agent browser access",
219 to: "/settings/integrations",
220 targetId: "browser",
221 },
222 {
223 id: "browser-default-viewport",
224 title: "Default browser viewport",
225 to: "/settings/integrations",
226 targetId: "browser",
227 },
228 {
229 id: "browser-default-zoom",
230 title: "Default browser zoom",
231 to: "/settings/integrations",
232 targetId: "browser",
233 },
234 {
235 id: "browser-default-appearance",
236 title: "Default browser appearance",
237 to: "/settings/integrations",
238 targetId: "browser",
239 },
240 {
241 id: "browser-auto-show-floating-preview",
242 title: "Auto-show floating preview",
243 to: "/settings/integrations",
244 targetId: "browser",
245 },
246 {
247 id: "source-control",
248 title: "Source control",
249 to: "/settings/source-control",
250 },
251 {
252 id: "remote-environments",
253 title: "Remote environments",
254 to: "/settings/connections",
255 },
256 {
257 id: "archive",
258 title: "Archived threads",
259 to: "/settings/archived",
260 },
261] as const satisfies ReadonlyArray<SettingsSearchItem>;
262
263export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
264
265const SEARCH_ITEMS_BY_ID = Object.fromEntries(
266 SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item]),
267) as Readonly<Record<SettingsSearchItemId, SettingsSearchItem>>;
268
269/**
270 * `id` and `title` props for the element a search item anchors to. Panels
271 * spread (or pick from) this instead of restating the strings, so the catalog
272 * and the rendered settings cannot drift apart.
273 */
274export function searchableSetting(id: SettingsSearchItemId): {
275 readonly id: string;
276 readonly title: string;
277} {
278 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID[id];
279 return { id: anchorId, title };
280}
281
282function normalizeSearchText(value: string): string {
283 return value
284 .normalize("NFKD")
285 .replace(/[\u0300-\u036f]/g, "")
286 .toLocaleLowerCase()
287 .replace(/\s+/g, " ")
288 .trim();
289}
290
291export function searchSettings(
292 query: string,
293 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
294): ReadonlyArray<SettingsSearchItem> {
295 const normalizedQuery = normalizeSearchText(query);
296 if (normalizedQuery.length === 0) return [];
297
298 return items.filter(
299 (item) =>
300 (isElectron || item.desktopOnly !== true) &&
301 normalizeSearchText(item.title).includes(normalizedQuery),
302 );
303}