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