-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSettingsDialog.tsx
More file actions
1947 lines (1833 loc) · 87.6 KB
/
SettingsDialog.tsx
File metadata and controls
1947 lines (1833 loc) · 87.6 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { Show, For, createSignal, createMemo, createEffect, onMount, onCleanup, JSX } from "solid-js";
import { Icon } from "./ui/Icon";
import { useTheme, Theme } from "@/context/ThemeContext";
import { useSDK } from "@/context/SDKContext";
import { useVim } from "@/context/VimContext";
import { useLLM } from "@/context/LLMContext";
import { useSupermaven } from "@/context/SupermavenContext";
import { useFormatter, type FormatterType } from "@/context/FormatterContext";
import { useSettings, type SettingsScope, type SettingSource, type CortexSettings, type ExplorerSortOrder, DEFAULT_SETTINGS } from "@/context/SettingsContext";
import { useWorkspace } from "@/context/WorkspaceContext";
import { useMultiRepo } from "@/context/MultiRepoContext";
import { KeymapEditor, Toggle, Select, SectionHeader, OptionCard, FormGroup, InfoBox, Button, Kbd, EditorSettingsPanel, TerminalSettingsPanel, FilesSettingsPanel, NetworkSettingsPanel, JsonSettingsEditor, GitSettingsPanel, DebugSettingsPanel } from "@/components/settings";
import { KeymapProvider } from "@/context/KeymapContext";
import { loadStylesheet } from "@/utils/lazyStyles";
loadStylesheet("settings");
import { CopilotSettingsPanel, CopilotSignInModal } from "@/components/ai/CopilotStatus";
import { ExtensionsPanel } from "@/components/extensions";
import { Button as UIButton, IconButton, Input, Card, Text, Badge } from "@/components/ui";
import type { LLMProviderType } from "@/utils/llm";
/**
* Safe accessor for explorer settings with fallback defaults.
* Prevents "Cannot read properties of undefined" errors when settings are corrupted or missing.
*/
function safeExplorerSettings(settings: CortexSettings | null | undefined) {
const explorer = settings?.explorer ?? DEFAULT_SETTINGS.explorer;
return {
sortOrder: explorer?.sortOrder ?? DEFAULT_SETTINGS.explorer.sortOrder,
};
}
/**
* Safe accessor for theme settings with fallback defaults.
*/
function safeThemeSettings(settings: CortexSettings | null | undefined) {
const theme = settings?.theme ?? DEFAULT_SETTINGS.theme;
return {
theme: theme?.theme ?? DEFAULT_SETTINGS.theme.theme,
wrapTabs: theme?.wrapTabs ?? DEFAULT_SETTINGS.theme.wrapTabs,
};
}
// Module-level signal to persist TOC section across re-renders / focus changes
const [persistedDialogSection, setPersistedDialogSection] = createSignal<string>("general");
/** Map tree item IDs to settings sections for modified count */
const TREE_ID_TO_SECTION: Record<string, keyof CortexSettings | null> = {
"common": null,
"general": "theme",
"explorer": "explorer",
"files": "files",
"security": "security",
"network": "http",
"editor-root": null,
"editor": "editor",
"formatting": "editor",
"keybindings": null,
"terminal": "terminal",
"git": "git",
"debug": "debug",
"ai": null,
"models": "ai",
"ai_completion": "ai",
"extensions": "extensions",
};
interface TreeItem {
id: string;
label: string;
icon?: any;
children?: TreeItem[];
}
const SETTINGS_TREE: TreeItem[] = [
{
id: "common",
label: "Common",
icon: () => <Icon name="desktop" />,
children: [
{ id: "general", label: "General" },
{ id: "explorer", label: "Explorer" },
{ id: "files", label: "Files" },
{ id: "security", label: "Security" },
{ id: "network", label: "Network" },
]
},
{
id: "editor-root",
label: "Editor",
icon: () => <Icon name="pen-to-square" />,
children: [
{ id: "editor", label: "Settings" },
{ id: "formatting", label: "Formatting" },
{ id: "keybindings", label: "Keybindings" },
]
},
{
id: "terminal",
label: "Terminal",
icon: () => <Icon name="terminal" />,
},
{
id: "git",
label: "Git",
icon: () => <Icon name="code-branch" />,
},
{
id: "debug",
label: "Debug",
icon: () => <Icon name="bug" />,
},
{
id: "ai",
label: "AI",
icon: () => <Icon name="microchip" />,
children: [
{ id: "models", label: "Models" },
{ id: "ai_completion", label: "AI Completion" },
]
},
{
id: "extensions",
label: "Extensions",
icon: () => <Icon name="puzzle-piece" />,
}
];
function SettingsTreeItem(props: {
item: TreeItem;
activeSection: string;
onSelect: (id: string) => void;
depth: number;
getModifiedCount: (itemId: string) => number;
showModifiedOnly: boolean;
}) {
const [isExpanded, setIsExpanded] = createSignal(true);
const hasChildren = () => props.item.children && props.item.children.length > 0;
const handleClick = (e: MouseEvent) => {
e.stopPropagation();
if (hasChildren()) {
setIsExpanded(!isExpanded());
}
props.onSelect(props.item.id);
};
// Get modified count for this item
const modifiedCount = () => props.getModifiedCount(props.item.id);
// Calculate total modified count including children
const totalModifiedCount = (): number => {
let total = modifiedCount();
if (props.item.children) {
for (const child of props.item.children) {
total += props.getModifiedCount(child.id);
}
}
return total;
};
// Check if this item or its children have modifications
const hasModifications = () => totalModifiedCount() > 0;
// Filter logic: if showModifiedOnly is true, only show items with modifications
const shouldShow = () => !props.showModifiedOnly || hasModifications();
const isActive = () => props.activeSection === props.item.id || (!isExpanded() && props.item.children?.some(c => c.id === props.activeSection));
return (
<Show when={shouldShow()}>
<div class="settings-tree-node">
<button
onClick={handleClick}
class={`settings-tab-button ${isActive() ? "settings-tab-button-active" : ""} ${hasModifications() ? "has-modifications" : ""}`}
style={{
display: "flex",
"align-items": "center",
width: "100%",
"min-width": "0",
gap: "6px",
padding: `4px 8px 4px ${8 + props.depth * 16}px`,
background: isActive() ? "var(--jb-list-active-bg, rgba(255,255,255,0.08))" : "transparent",
border: "none",
"border-radius": "var(--cortex-radius-sm, 6px)",
cursor: "pointer",
color: isActive() ? "var(--jb-text-body-color, #fff)" : "var(--jb-text-muted-color, rgba(255,255,255,0.7))",
"font-size": "13px",
"font-weight": isActive() ? "500" : "400",
"font-family": "inherit",
"text-align": "left",
height: "30px",
"margin-bottom": "1px",
transition: "background 0.1s, color 0.1s",
}}
onMouseEnter={(e) => {
if (!isActive()) {
e.currentTarget.style.background = "var(--jb-list-hover-bg, rgba(255,255,255,0.04))";
}
}}
onMouseLeave={(e) => {
if (!isActive()) {
e.currentTarget.style.background = "transparent";
}
}}
>
<span style={{ width: "14px", "flex-shrink": "0", display: "flex", "align-items": "center", "justify-content": "center" }}>
<Show when={hasChildren()}>
<Show when={isExpanded()} fallback={<Icon name="chevron-right" style={{ width: "12px", height: "12px" }} />}>
<Icon name="chevron-down" style={{ width: "12px", height: "12px" }} />
</Show>
</Show>
</span>
<Show when={props.item.icon}>
<span style={{ width: "16px", height: "16px", display: "inline-flex", "align-items": "center", "justify-content": "center", "flex-shrink": "0" }}>
<props.item.icon />
</span>
</Show>
<span style={{ flex: "1", overflow: "hidden", "white-space": "nowrap", "text-overflow": "ellipsis" }}>{props.item.label}</span>
<Show when={totalModifiedCount() > 0}>
<span title={`${totalModifiedCount()} modified setting${totalModifiedCount() > 1 ? 's' : ''}`}>
<Badge size="sm">
{totalModifiedCount()}
</Badge>
</span>
</Show>
</button>
<Show when={hasChildren() && isExpanded()}>
<div class="settings-tree-children">
<For each={props.item.children}>
{(child) => (
<SettingsTreeItem
item={child}
activeSection={props.activeSection}
onSelect={props.onSelect}
depth={props.depth + 1}
getModifiedCount={props.getModifiedCount}
showModifiedOnly={props.showModifiedOnly}
/>
)}
</For>
</div>
</Show>
</div>
</Show>
);
}
interface SettingsDialogProps {
isOpen: boolean;
onClose: () => void;
/** Initial JSON view state */
initialJsonView?: boolean;
/** Initial show default settings state (only applies when in JSON view) */
initialShowDefaults?: boolean;
/** Initial section to scroll to (e.g., "keybindings") */
initialSection?: string;
}
/** Badge showing where a setting value comes from */
function SettingSourceBadge(props: { source: SettingSource; hasOverride?: boolean }) {
const getVariant = (): "accent" | "success" | "default" => {
switch (props.source) {
case "workspace":
return "success"; // Purple-ish, using success as closest
case "user":
return "accent";
default:
return "default";
}
};
const getLabel = () => {
switch (props.source) {
case "workspace":
return "Workspace";
case "user":
return "User";
default:
return "Default";
}
};
const customStyle = (): JSX.CSSProperties => {
if (props.source === "workspace") {
return {
background: "rgba(168, 85, 247, 0.2)",
color: "var(--cortex-info)",
border: "1px solid rgba(168, 85, 247, 0.3)",
};
}
return {};
};
return (
<Badge variant={getVariant()} size="sm" style={customStyle()}>
{getLabel()}
</Badge>
);
}
/** Visual indicator dot for workspace overrides */
function WorkspaceOverrideIndicator(props: { hasOverride: boolean }) {
return (
<Show when={props.hasOverride}>
<span
class="inline-block w-2 h-2 rounded-full bg-purple-500"
title="This setting has a workspace override"
/>
</Show>
);
}
/** Setting row with source indicator and reset button */
function SettingRow(props: {
label: string;
source: SettingSource;
hasOverride: boolean;
onReset?: () => void;
children: JSX.Element;
}) {
return (
<div class="settings-row group relative">
<div class="flex items-center gap-2">
<WorkspaceOverrideIndicator hasOverride={props.hasOverride} />
<span class="settings-row-label">{props.label}</span>
<SettingSourceBadge source={props.source} />
</div>
<div class="flex items-center gap-2">
{props.children}
<Show when={props.hasOverride && props.onReset}>
<IconButton
onClick={props.onReset}
size="sm"
class="opacity-0 group-hover:opacity-100 transition-opacity"
title="Reset to user setting"
>
<Icon name="rotate-left" class="h-3 w-3" />
</IconButton>
</Show>
</div>
</div>
);
}
export function SettingsDialog(props: SettingsDialogProps) {
const { setTheme } = useTheme();
const { state, updateConfig } = useSDK();
const vim = useVim();
const llm = useLLM();
const supermaven = useSupermaven();
const formatter = useFormatter();
useMultiRepo(); // Context provider hook (values not destructured yet)
const settings = useSettings();
const activeTab = persistedDialogSection;
const setActiveTab = setPersistedDialogSection;
const [searchQuery, setSearchQuery] = createSignal("");
// Apply initialSection only on first mount when explicitly provided
onMount(() => {
if (props.initialSection) {
setActiveTab(props.initialSection);
setTimeout(() => {
scrollToSection(props.initialSection!);
}, 100);
}
});
// Removed unused signals: supermavenApiKey, showSupermavenKey
const [showCopilotSignIn, setShowCopilotSignIn] = createSignal(false);
// Settings scope toggle: user vs workspace
const [settingsScope, setSettingsScope] = createSignal<SettingsScope>("user");
// JSON view mode toggle
const [showJsonView, setShowJsonView] = createSignal(props.initialJsonView ?? false);
const [jsonViewDirty, setJsonViewDirty] = createSignal(false);
// Initial value for showing default settings side panel (passed to JsonSettingsEditor)
const initialShowDefaults = props.initialShowDefaults ?? false;
// Modified settings filter
const [showModifiedOnly, setShowModifiedOnly] = createSignal(false);
// Get modified count for a tree item
const getModifiedCount = (itemId: string): number => {
const section = TREE_ID_TO_SECTION[itemId];
if (!section) return 0;
return settings.getModifiedCountForSection(section);
};
// Get total modified settings count
const totalModifiedCount = createMemo(() => {
return settings.getAllModifiedSettings().length;
});
const [showApiKeys, setShowApiKeys] = createSignal<Record<LLMProviderType, boolean>>({
anthropic: false,
openai: false,
google: false,
mistral: false,
deepseek: false,
openrouter: false,
});
const [apiKeyInputs, setApiKeyInputs] = createSignal<Record<LLMProviderType, string>>({
anthropic: "",
openai: "",
google: "",
mistral: "",
deepseek: "",
openrouter: "",
});
const [validatingProvider, setValidatingProvider] = createSignal<LLMProviderType | null>(null);
const [, setContentRef] = createSignal<HTMLDivElement | null>(null);
const findTreeItem = (items: TreeItem[], id: string): TreeItem | undefined => {
for (const item of items) {
if (item.id === id) return item;
if (item.children) {
const found = findTreeItem(item.children, id);
if (found) return found;
}
}
return undefined;
};
const scrollToSection = (id: string) => {
const element = document.getElementById(`settings-section-${id}`);
if (element) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
setActiveTab(id);
} else {
const item = findTreeItem(SETTINGS_TREE, id);
if (item && item.children && item.children.length > 0) {
scrollToSection(item.children[0].id);
} else {
setActiveTab(id);
}
}
};
// Check if workspace is available
const hasWorkspace = createMemo(() => settings.hasWorkspace());
const workspacePath = createMemo(() => settings.workspacePath());
// Multi-root workspace support
const workspace = useWorkspace();
const isMultiRoot = createMemo(() => workspace.isMultiRoot());
const workspaceFolders = createMemo(() => workspace.folders());
// Selected folder for folder-level settings
const [selectedFolder, setSelectedFolder] = createSignal<string | null>(null);
// Initialize selected folder when scope changes to "folder"
createEffect(() => {
if (settingsScope() === "folder" && !selectedFolder() && workspaceFolders().length > 0) {
setSelectedFolder(workspaceFolders()[0].path);
}
});
const toggleShowApiKey = (provider: LLMProviderType) => {
setShowApiKeys(prev => ({ ...prev, [provider]: !prev[provider] }));
};
const handleApiKeyChange = (provider: LLMProviderType, value: string) => {
setApiKeyInputs(prev => ({ ...prev, [provider]: value }));
};
const saveApiKey = (provider: LLMProviderType) => {
const key = apiKeyInputs()[provider];
if (key) {
llm.setApiKey(provider, key);
setApiKeyInputs(prev => ({ ...prev, [provider]: "" }));
}
};
const validateProvider = async (provider: LLMProviderType) => {
setValidatingProvider(provider);
await llm.refreshProviderStatus(provider);
setValidatingProvider(null);
};
const getProviderIcon = (type: LLMProviderType): string => {
const icons: Record<LLMProviderType, string> = {
anthropic: "🤖",
openai: "🧠",
google: "🔷",
mistral: "💨",
deepseek: "🌊",
openrouter: "🔀",
};
return icons[type];
};
const usageStats = createMemo(() => llm.getUsageStats());
const providerStatuses = createMemo(() => llm.getProviderStatuses());
const themes: { value: Theme; label: string; icon: () => JSX.Element }[] = [
{ value: "dark", label: "Dark", icon: () => <Icon name="moon" /> },
{ value: "light", label: "Light", icon: () => <Icon name="sun" /> },
{ value: "system", label: "System", icon: () => <Icon name="desktop" /> },
];
const sandboxModes = [
{ value: "workspace_write", label: "Workspace Write", description: "Write access within workspace" },
{ value: "directory_only", label: "Directory Only", description: "Restricted to current directory" },
{ value: "read_only", label: "Read Only", description: "No write access" },
];
const approvalModes = [
{ value: "auto", label: "Auto Approve", description: "Automatically approve safe operations" },
{ value: "ask_edit", label: "Ask for Edits", description: "Ask before file modifications" },
{ value: "ask_all", label: "Ask All", description: "Ask before any operation" },
];
const formatterDisplayNames: Record<FormatterType, string> = {
prettier: "Prettier",
rustfmt: "rustfmt",
black: "Black",
gofmt: "gofmt",
clangformat: "clang-format",
biome: "Biome",
deno: "Deno",
};
const getFormatterIcon = (type: FormatterType): string => {
const icons: Record<FormatterType, string> = {
prettier: "✨",
rustfmt: "🦀",
black: "🐍",
gofmt: "🐹",
clangformat: "⚙️",
biome: "🌿",
deno: "🦕",
};
return icons[type];
};
// Get workspace folder name for display
const workspaceName = createMemo(() => {
const path = workspacePath();
if (!path) return null;
const parts = path.replace(/\\/g, "/").split("/");
return parts[parts.length - 1] || parts[parts.length - 2];
});
// Dialog reference for focus trapping
const [dialogRef, setDialogRef] = createSignal<HTMLDivElement | null>(null);
// Focus trapping implementation - VS Code spec
const getFocusableElements = () => {
const dialog = dialogRef();
if (!dialog) return [];
return Array.from(
dialog.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
)
).filter(el => !el.hasAttribute('disabled') && el.offsetParent !== null);
};
const handleKeyDown = (e: KeyboardEvent) => {
if (!props.isOpen) return;
// Escape key closes dialog
if (e.key === "Escape") {
e.preventDefault();
if (showJsonView() && jsonViewDirty()) {
if (!window.confirm("You have unsaved changes in the JSON editor. Close anyway? Changes will be lost.")) return;
}
props.onClose();
return;
}
// Tab key focus trapping with circular navigation
if (e.key === "Tab") {
const focusable = getFocusableElements();
if (focusable.length === 0) return;
const firstElement = focusable[0];
const lastElement = focusable[focusable.length - 1];
const activeElement = document.activeElement;
if (e.shiftKey) {
// Shift+Tab: go backwards
if (activeElement === firstElement || !focusable.includes(activeElement as HTMLElement)) {
e.preventDefault();
lastElement.focus();
}
} else {
// Tab: go forwards
if (activeElement === lastElement || !focusable.includes(activeElement as HTMLElement)) {
e.preventDefault();
firstElement.focus();
}
}
}
// Prevent Alt key shortcuts within dialog
if (e.altKey) {
e.preventDefault();
}
};
// Handle backdrop click - return focus to dialog
const handleBackdropClick = (e: MouseEvent) => {
if (e.target === e.currentTarget) {
props.onClose();
}
};
// Set up keyboard event listener
onMount(() => {
window.addEventListener("keydown", handleKeyDown);
});
onCleanup(() => {
window.removeEventListener("keydown", handleKeyDown);
});
// Set up focus management when dialog opens
createEffect(() => {
if (props.isOpen) {
// Focus the search input when dialog opens
setTimeout(() => {
const focusable = getFocusableElements();
if (focusable.length > 0) {
// Find the search input as preferred initial focus
const searchInput = focusable.find(el => el.getAttribute('placeholder')?.includes('Search'));
if (searchInput) {
searchInput.focus();
} else {
focusable[0].focus();
}
}
}, 0);
}
});
return (
<Show when={props.isOpen}>
{/* Modal Backdrop - VS Code: z-index 2575, rgba(0,0,0,0.3) */}
<div
class="modal-overlay dimmed"
onClick={handleBackdropClick}
>
{/* Dialog Shadow Wrapper */}
<div class="dialog-shadow">
{/* Settings Dialog - JetBrains New UI */}
<div
ref={setDialogRef}
class="settings-editor mx-4 w-full transition-all"
style={{
"max-width": "1200px",
"min-width": "var(--dialog-min-width)",
"max-height": "90vh",
"border-radius": "var(--jb-radius-lg)",
"border": "1px solid var(--jb-border-default)",
"background": "var(--jb-modal)",
"box-shadow": "var(--jb-shadow-modal)",
}}
role="dialog"
aria-modal="true"
aria-labelledby="settings-dialog-title"
tabIndex={-1}
data-focus-trap="true"
onClick={(e) => e.stopPropagation()}
>
{/* Header - JetBrains New UI: 24px horizontal padding */}
<div class="settings-header flex items-center justify-between" style={{
"padding-left": "24px",
"padding-right": "24px",
"padding-top": "11px",
"padding-bottom": "16px",
"border-bottom": "1px solid var(--jb-border-default)",
"background": "var(--jb-panel)",
"flex-wrap": "wrap",
"gap": "8px",
}}>
<div class="flex items-center gap-4" style={{ "flex-wrap": "wrap", "min-width": "0" }}>
<Text as="h2" size="lg" weight="semibold" style={{ color: "var(--jb-text-body-color)", "white-space": "nowrap", "flex-shrink": "0" }}>Settings</Text>
{/* Settings Scope Toggle */}
<div style={{
display: "flex",
"align-items": "center",
gap: "4px",
"border-radius": "var(--jb-radius-lg)",
border: "1px solid var(--jb-border-default)",
background: "var(--jb-input-bg)",
padding: "2px",
}}>
<UIButton
onClick={() => setSettingsScope("user")}
variant={settingsScope() === "user" ? "primary" : "ghost"}
size="sm"
style={{
display: "flex",
"align-items": "center",
gap: "6px",
padding: "4px 12px",
"border-radius": "var(--jb-radius-sm)",
"font-size": "var(--jb-text-muted-size)",
"font-weight": "500",
}}
title="User Settings (~/.cortex/settings.json)"
>
<Icon name="user" style={{ width: "12px", height: "12px" }} />
User
</UIButton>
<UIButton
onClick={() => setSettingsScope("workspace")}
disabled={!hasWorkspace()}
variant={settingsScope() === "workspace" ? "primary" : "ghost"}
size="sm"
style={{
display: "flex",
"align-items": "center",
gap: "6px",
padding: "4px 12px",
"border-radius": "var(--jb-radius-sm)",
"font-size": "var(--jb-text-muted-size)",
"font-weight": "500",
opacity: hasWorkspace() ? "1" : "0.5",
background: settingsScope() === "workspace" ? "var(--cortex-info)" : "transparent",
color: settingsScope() === "workspace" ? "#fff" : "var(--jb-text-muted-color)",
}}
title={hasWorkspace()
? `Workspace Settings (.cortex/settings.json in ${workspaceName()})`
: "No workspace open"}
>
<Icon name="folder" style={{ width: "12px", height: "12px" }} />
Workspace
</UIButton>
{/* Folder scope - only shown in multi-root workspaces */}
<Show when={isMultiRoot()}>
<UIButton
onClick={() => setSettingsScope("folder")}
variant={settingsScope() === "folder" ? "primary" : "ghost"}
size="sm"
style={{
display: "flex",
"align-items": "center",
gap: "6px",
padding: "4px 12px",
"border-radius": "var(--jb-radius-sm)",
"font-size": "var(--jb-text-muted-size)",
"font-weight": "500",
background: settingsScope() === "folder" ? "var(--cortex-success)" : "transparent",
color: settingsScope() === "folder" ? "#fff" : "var(--jb-text-muted-color)",
}}
title="Folder Settings ({folder}/.cortex/settings.json)"
>
<Icon name="folder" style={{ width: "12px", height: "12px" }} />
Folder
</UIButton>
</Show>
</div>
{/* Folder selector - shown when folder scope is active */}
<Show when={settingsScope() === "folder" && isMultiRoot()}>
<select
aria-label="Select workspace folder for folder-specific settings"
value={selectedFolder() || ""}
onChange={(e) => setSelectedFolder(e.currentTarget.value)}
style={{
"border-radius": "var(--jb-radius-lg)",
border: "1px solid rgba(5, 150, 105, 0.3)",
background: "rgba(5, 150, 105, 0.1)",
padding: "4px 12px",
"font-size": "var(--jb-text-muted-size)",
"font-weight": "500",
color: "var(--cortex-success)",
}}
>
<For each={workspaceFolders()}>
{(folder) => (
<option value={folder.path} style={{ background: "var(--jb-panel)", color: "var(--jb-text-body-color)" }}>
{folder.name}
</option>
)}
</For>
</select>
</Show>
<div style={{ position: "relative" }}>
<Icon name="magnifying-glass" style={{
position: "absolute",
left: "12px",
top: "50%",
transform: "translateY(-50%)",
width: "16px",
height: "16px",
color: "var(--jb-text-muted-color)",
"pointer-events": "none",
"z-index": "1",
}} />
<Input
type="text"
placeholder="Search settings..."
value={searchQuery()}
onInput={(e) => setSearchQuery(e.currentTarget.value)}
style={{
width: "256px",
"padding-left": "36px",
"padding-right": "32px",
}}
/>
<Show when={searchQuery()}>
<IconButton
onClick={() => setSearchQuery("")}
size="sm"
style={{
position: "absolute",
right: "4px",
top: "50%",
transform: "translateY(-50%)",
}}
>
<Icon name="xmark" />
</IconButton>
</Show>
</div>
</div>
<div style={{ display: "flex", "align-items": "center", gap: "8px" }}>
{/* JSON/GUI Toggle Button */}
<UIButton
onClick={() => {
if (showJsonView() && jsonViewDirty()) {
const confirmed = window.confirm(
"You have unsaved changes in the JSON editor. Switch anyway? Changes will be lost."
);
if (!confirmed) return;
}
setShowJsonView(!showJsonView());
setJsonViewDirty(false);
}}
variant={showJsonView() ? "secondary" : "ghost"}
size="sm"
icon={showJsonView() ? <Icon name="gear" style={{ width: "14px", height: "14px" }} /> : <Icon name="file-lines" style={{ width: "14px", height: "14px" }} />}
class={showJsonView() ? "settings-json-toggle-active" : ""}
title={showJsonView() ? "Switch to GUI Settings" : "Open Settings (JSON)"}
>
{showJsonView() ? "GUI Settings" : "JSON"}
</UIButton>
{/* Close Button */}
<IconButton
onClick={() => {
if (showJsonView() && jsonViewDirty()) {
const confirmed = window.confirm(
"You have unsaved changes in the JSON editor. Close anyway? Changes will be lost."
);
if (!confirmed) return;
}
props.onClose();
}}
size="lg"
>
<Icon name="xmark" style={{ width: "20px", height: "20px" }} />
</IconButton>
</div>
</div>
{/* Active Modified Filter Chip */}
<Show when={showModifiedOnly()}>
<div style={{
display: "flex",
"align-items": "center",
gap: "6px",
padding: "6px 24px",
"border-bottom": "1px solid var(--jb-border-default)",
"flex-wrap": "wrap",
}}>
<div style={{
display: "flex",
"align-items": "center",
gap: "4px",
padding: "2px 8px",
background: "rgba(234, 179, 8, 0.2)",
border: "1px solid rgba(234, 179, 8, 0.4)",
"border-radius": "var(--cortex-radius-sm, 6px)",
"font-size": "11px",
color: "var(--cortex-warning)",
}}>
<span>@modified</span>
<button
onClick={() => setShowModifiedOnly(false)}
style={{
background: "transparent",
border: "none",
cursor: "pointer",
padding: "0",
display: "flex",
"align-items": "center",
color: "var(--cortex-warning)",
}}
>
<Icon name="xmark" style={{ width: "12px", height: "12px" }} />
</button>
</div>
</div>
</Show>
{/* Workspace Info Banner */}
<Show when={settingsScope() === "workspace" && hasWorkspace()}>
<div style={{
padding: "8px 24px",
background: "rgba(168, 85, 247, 0.1)",
"border-bottom": "1px solid rgba(168, 85, 247, 0.2)",
}}>
<div style={{ display: "flex", "align-items": "center", gap: "8px" }}>
<Icon name="folder" style={{ width: "12px", height: "12px", color: "var(--cortex-info)" }} />
<Text size="xs" style={{ color: "var(--cortex-info)" }}>
Editing workspace settings for <strong>{workspaceName()}</strong>
</Text>
<Text size="xs" style={{ color: "rgba(168, 85, 247, 0.6)" }}>
— Settings here override your user settings for this workspace only
</Text>
</div>
</div>
</Show>
{/* Folder Info Banner */}
<Show when={settingsScope() === "folder" && selectedFolder()}>
<div style={{
padding: "8px 24px",
background: "rgba(16, 185, 129, 0.1)",
"border-bottom": "1px solid rgba(16, 185, 129, 0.2)",
}}>
<div style={{ display: "flex", "align-items": "center", gap: "8px" }}>
<Icon name="folder" style={{ width: "12px", height: "12px", color: "var(--cortex-success)" }} />
<Text size="xs" style={{ color: "var(--cortex-success)" }}>
Editing folder settings for <strong>{workspaceFolders().find(f => f.path === selectedFolder())?.name || selectedFolder()}</strong>
</Text>
<Text size="xs" style={{ color: "rgba(16, 185, 129, 0.6)" }}>
— Settings here override user and workspace settings for files in this folder only
</Text>
</div>
</div>
</Show>
{/* JSON Settings Editor View */}
<Show when={showJsonView()}>
<div class="h-[calc(90vh-120px)] overflow-hidden">
<JsonSettingsEditor
initialScope={settingsScope()}
initialShowDefaults={initialShowDefaults}
onSave={() => {
// Reload settings after JSON save
settings.loadSettings();
}}
onDirtyChange={(dirty) => setJsonViewDirty(dirty)}
/>
</div>
</Show>
{/* GUI Settings View */}
<Show when={!showJsonView()}>
<div style={{ display: "flex", height: "calc(90vh - 120px)", overflow: "hidden" }}>
{/* Sidebar */}
<div class="settings-sidebar" style={{
width: "256px",
"min-width": "120px",
"border-right": "1px solid var(--jb-border-default)",
"overflow-y": "auto",
"overflow-x": "hidden",
padding: "8px",
"flex-shrink": "1",
background: "var(--jb-panel)",
}}>
{/* Modified filter toggle */}
<div style={{
"margin-bottom": "8px",
"padding-bottom": "8px",
"border-bottom": "1px solid var(--jb-border-default)",
}}>
<UIButton
onClick={() => setShowModifiedOnly(!showModifiedOnly())}
variant={showModifiedOnly() ? "secondary" : "ghost"}
style={{
display: "flex",
"align-items": "center",
gap: "8px",
width: "100%",
padding: "6px 12px",
"border-radius": "var(--jb-radius-sm)",
"font-size": "var(--jb-text-muted-size)",
"font-weight": "500",
"justify-content": "flex-start",
background: showModifiedOnly() ? "rgba(234, 179, 8, 0.2)" : "transparent",
color: showModifiedOnly() ? "var(--cortex-warning)" : "var(--jb-text-muted-color)",
border: showModifiedOnly() ? "1px solid rgba(234, 179, 8, 0.3)" : "1px solid transparent",
}}
title={showModifiedOnly() ? "Show all settings" : "Show only modified settings"}
>
<Icon name="filter" style={{ width: "14px", height: "14px" }} />
<Text size="sm" style={{ flex: "1", "text-align": "left", overflow: "hidden", "white-space": "nowrap", "text-overflow": "ellipsis" }}>Modified</Text>
<Show when={totalModifiedCount() > 0}>
<Badge
size="sm"
style={showModifiedOnly() ? {
background: "rgba(234, 179, 8, 0.3)",
color: "var(--cortex-warning)",