Open History to see the last commit
1export type SettingsPath =
2 | "/settings/general"
3 | "/settings/appearance"
4 | "/settings/keybindings"
5 | "/settings/providers"
6 | "/settings/source-control"
7 | "/settings/connections"
8 | "/settings/beta"
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/providers": "Providers",
27 "/settings/source-control": "Source Control",
28 "/settings/connections": "Connections",
29 "/settings/beta": "Beta",
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: "theme",
42 title: "Theme",
43 to: "/settings/appearance",
44 },
45 {
46 // Prefixed because the slider control already owns the `glass-opacity` id.
47 id: "setting-glass-opacity",
48 title: "Glass opacity",
49 to: "/settings/appearance",
50 },
51 {
52 id: "environment-identification",
53 title: "Environment identification",
54 to: "/settings/appearance",
55 // The setting is stage-dependent, so its parent section is the stable destination.
56 targetId: "appearance",
57 },
58 {
59 id: "word-wrap",
60 title: "Word wrap",
61 to: "/settings/appearance",
62 },
63 {
64 id: "project-grouping",
65 title: "Project grouping",
66 to: "/settings/general",
67 },
68 {
69 id: "time-format",
70 title: "Time format",
71 to: "/settings/general",
72 },
73 {
74 id: "hide-whitespace-changes",
75 title: "Hide whitespace changes",
76 to: "/settings/general",
77 },
78 {
79 id: "assistant-output",
80 title: "Assistant output",
81 to: "/settings/general",
82 },
83 {
84 id: "provider-update-checks",
85 title: "Provider update checks",
86 to: "/settings/general",
87 },
88 {
89 id: "auto-open-task-panel",
90 title: "Auto-open task panel",
91 to: "/settings/general",
92 },
93 {
94 id: "new-threads",
95 title: "New threads",
96 to: "/settings/general",
97 },
98 {
99 id: "start-from-origin",
100 title: "Start from origin",
101 to: "/settings/general",
102 targetId: "new-threads",
103 },
104 {
105 id: "add-project-starts-in",
106 title: "Add project starts in",
107 to: "/settings/general",
108 },
109 {
110 id: "archive-confirmation",
111 title: "Archive confirmation",
112 to: "/settings/general",
113 },
114 {
115 id: "delete-confirmation",
116 title: "Delete confirmation",
117 to: "/settings/general",
118 },
119 {
120 id: "text-generation-model",
121 title: "Text generation model",
122 to: "/settings/general",
123 },
124 {
125 id: "diagnostics",
126 title: "Diagnostics",
127 to: "/settings/general",
128 },
129 {
130 id: "keybindings",
131 title: "Keybindings",
132 to: "/settings/keybindings",
133 },
134 {
135 id: "providers",
136 title: "Providers",
137 to: "/settings/providers",
138 },
139 {
140 id: "source-control",
141 title: "Source control",
142 to: "/settings/source-control",
143 },
144 {
145 id: "remote-environments",
146 title: "Remote environments",
147 to: "/settings/connections",
148 },
149 {
150 id: "sidebar-v2",
151 title: "Sidebar v2",
152 to: "/settings/beta",
153 },
154 {
155 id: "auto-settle-inactive-threads",
156 title: "Auto-settle inactive threads",
157 to: "/settings/beta",
158 targetId: "sidebar-v2",
159 },
160 {
161 id: "archive",
162 title: "Archived threads",
163 to: "/settings/archived",
164 },
165] as const satisfies ReadonlyArray<SettingsSearchItem>;
166
167export type SettingsSearchItemId = (typeof SETTINGS_SEARCH_ITEMS)[number]["id"];
168
169const SEARCH_ITEMS_BY_ID = Object.fromEntries(
170 SETTINGS_SEARCH_ITEMS.map((item) => [item.id, item]),
171) as Readonly<Record<SettingsSearchItemId, SettingsSearchItem>>;
172
173/**
174 * `id` and `title` props for the element a search item anchors to. Panels
175 * spread (or pick from) this instead of restating the strings, so the catalog
176 * and the rendered settings cannot drift apart.
177 */
178export function searchableSetting(id: SettingsSearchItemId): {
179 readonly id: string;
180 readonly title: string;
181} {
182 const { id: anchorId, title } = SEARCH_ITEMS_BY_ID[id];
183 return { id: anchorId, title };
184}
185
186function normalizeSearchText(value: string): string {
187 return value
188 .normalize("NFKD")
189 .replace(/[\u0300-\u036f]/g, "")
190 .toLocaleLowerCase()
191 .replace(/\s+/g, " ")
192 .trim();
193}
194
195export function searchSettings(
196 query: string,
197 items: ReadonlyArray<SettingsSearchItem> = SETTINGS_SEARCH_ITEMS,
198): ReadonlyArray<SettingsSearchItem> {
199 const normalizedQuery = normalizeSearchText(query);
200 if (normalizedQuery.length === 0) return [];
201
202 return items.filter((item) => normalizeSearchText(item.title).includes(normalizedQuery));
203}