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 `glass-opacity` id.
62 id: "setting-glass-opacity",
63 title: "Glass opacity",
64 to: "/settings/appearance",
65 },
66 {
67 id: "environment-identification",
68 title: "Environment identification",
69 to: "/settings/appearance",
70 // The setting is stage-dependent, so its parent section is the stable destination.
71 targetId: "appearance",
72 },
73 {
74 id: "interface-font",
75 title: "Interface font",
76 to: "/settings/appearance",
77 },
78 {
79 id: "prompt-font",
80 title: "Prompt font",
81 to: "/settings/appearance",
82 },
83 {
84 id: "code-font",
85 title: "Code font",
86 to: "/settings/appearance",
87 },
88 {
89 id: "terminal-font",
90 title: "Terminal font",
91 to: "/settings/appearance",
92 },
93 {
94 id: "font-smoothing",
95 title: "Font smoothing",
96 to: "/settings/appearance",
97 },
98 {
99 id: "word-wrap",
100 title: "Word wrap",
101 to: "/settings/appearance",
102 },
103 {
104 id: "project-grouping",
105 title: "Project grouping",
106 to: "/settings/general",
107 },
108 {
109 id: "auto-settle-inactive-threads",
110 title: "Auto-settle inactive threads",
111 to: "/settings/general",
112 },
113 {
114 id: "auto-settle-merged-threads",
115 title: "Auto-settle merged threads",
116 to: "/settings/general",
117 },
118 {
119 id: "time-format",
120 title: "Time format",
121 to: "/settings/general",
122 },
123 {
124 id: "hide-whitespace-changes",
125 title: "Hide whitespace changes",
126 to: "/settings/general",
127 },
128 {
129 id: "provider-update-checks",
130 title: "Provider update checks",
131 to: "/settings/general",
132 },
133 {
134 id: "new-threads",
135 title: "New threads",
136 to: "/settings/general",
137 },
138 {
139 id: "start-from-origin",
140 title: "Start from origin",
141 to: "/settings/general",
142 targetId: "new-threads",
143 },
144 {
145 id: "add-project-starts-in",
146 title: "Add project starts in",
147 to: "/settings/general",
148 },
149 {
150 id: "archive-confirmation",
151 title: "Archive confirmation",
152 to: "/settings/general",
153 },
154 {
155 id: "delete-confirmation",
156 title: "Delete confirmation",
157 to: "/settings/general",
158 },
159 {
160 id: "quit-confirmation",
161 title: "Hold to quit",
162 to: "/settings/general",
163 desktopOnly: true,
164 },
165 {
166 id: "text-generation-model",
167 title: "Text generation model",
168 to: "/settings/general",
169 },
170 {
171 id: "diagnostics",
172 title: "Diagnostics",
173 to: "/settings/general",
174 },
175 {
176 id: "legacy-plan-mode",
177 title: "Plan mode (legacy)",
178 to: "/settings/general",
179 },
180 {
181 id: "legacy-token-streaming",
182 title: "Stream token by token (legacy)",
183 to: "/settings/general",
184 },
185 {
186 id: "legacy-sidebar",
187 title: "Sidebar (legacy)",
188 to: "/settings/general",
189 },
190 {
191 id: "keybindings",
192 title: "Keybindings",
193 to: "/settings/keybindings",
194 },
195 {
196 id: "providers",
197 title: "Providers",
198 to: "/settings/providers",
199 },
200 {
201 id: "agent-browser-access",
202 title: "Agent browser access",
203 to: "/settings/integrations",
204 targetId: "browser",
205 },
206 {
207 id: "browser-default-viewport",
208 title: "Default browser viewport",
209 to: "/settings/integrations",
210 targetId: "browser",
211 },
212 {
213 id: "browser-default-zoom",
214 title: "Default browser zoom",
215 to: "/settings/integrations",
216 targetId: "browser",
217 },
218 {
219 id: "browser-default-appearance",
220 title: "Default browser appearance",
221 to: "/settings/integrations",
222 targetId: "browser",
223 },
224 {
225 id: "browser-auto-show-floating-preview",
226 title: "Auto-show floating preview",
227 to: "/settings/integrations",
228 targetId: "browser",
229 },
230 {
231 id: "source-control",
232 title: "Source control",
233 to: "/settings/source-control",
234 },
235 {
236 id: "remote-environments",
237 title: "Remote environments",
238 to: "/settings/connections",
239 },
240 {
241 id: "archive",
242 title: "Archived threads",
243 to: "/settings/archived",
244 },
245] as const satisfies ReadonlyArray<SettingsSearchItem>;
246
247export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
248
249const SEARCH_ITEMS_BY_ID = Object.fromEntries(
250 SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item]),
251) as Readonly<Record<SettingsSearchItemId, SettingsSearchItem>>;
252
253/**
254 * `id` and `title` props for the element a search item anchors to. Panels
255 * spread (or pick from) this instead of restating the strings, so the catalog
256 * and the rendered settings cannot drift apart.
257 */
258export function searchableSetting(id: SettingsSearchItemId): {
259 readonly id: string;
260 readonly title: string;
261} {
262 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID[id];
263 return { id: anchorId, title };
264}
265
266function normalizeSearchText(value: string): string {
267 return value
268 .normalize("NFKD")
269 .replace(/[\u0300-\u036f]/g, "")
270 .toLocaleLowerCase()
271 .replace(/\s+/g, " ")
272 .trim();
273}
274
275export function searchSettings(
276 query: string,
277 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
278): ReadonlyArray<SettingsSearchItem> {
279 const normalizedQuery = normalizeSearchText(query);
280 if (normalizedQuery.length === 0) return [];
281
282 return items.filter(
283 (item) =>
284 (isElectron || item.desktopOnly !== true) &&
285 normalizeSearchText(item.title).includes(normalizedQuery),
286 );
287}