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