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