Skip to content

Commit 32b7dde

Browse files
authored
Merge pull request #796 from RooVetGit/v3.3.12
V3.3.12
2 parents dd174b9 + 80f6d20 commit 32b7dde

File tree

2 files changed

+37
-40
lines changed

2 files changed

+37
-40
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Bug fix to changing a mode's API configuration on the prompts tab

webview-ui/src/components/prompts/PromptsView.tsx

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
6666
const [isToolsEditMode, setIsToolsEditMode] = useState(false)
6767
const [isCreateModeDialogOpen, setIsCreateModeDialogOpen] = useState(false)
6868
const [activeSupportTab, setActiveSupportTab] = useState<SupportPromptType>("ENHANCE")
69-
const [selectedModeTab, setSelectedModeTab] = useState<string>(mode)
7069

7170
// Direct update functions
7271
const updateAgentPrompt = useCallback(
@@ -112,23 +111,26 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
112111
text: slug,
113112
})
114113
}, [])
115-
// Handle mode tab selection without actually switching modes
114+
115+
// Handle mode switching with explicit state initialization
116116
const handleModeSwitch = useCallback(
117117
(modeConfig: ModeConfig) => {
118-
if (modeConfig.slug === selectedModeTab) return // Prevent unnecessary updates
118+
if (modeConfig.slug === mode) return // Prevent unnecessary updates
119+
120+
// First switch the mode
121+
switchMode(modeConfig.slug)
119122

120-
// Update selected tab and reset tools edit mode
121-
setSelectedModeTab(modeConfig.slug)
123+
// Exit tools edit mode when switching modes
122124
setIsToolsEditMode(false)
123125
},
124-
[selectedModeTab, setIsToolsEditMode],
126+
[mode, switchMode, setIsToolsEditMode],
125127
)
126128

127129
// Helper function to get current mode's config
128130
const getCurrentMode = useCallback((): ModeConfig | undefined => {
129-
const findMode = (m: ModeConfig): boolean => m.slug === selectedModeTab
131+
const findMode = (m: ModeConfig): boolean => m.slug === mode
130132
return customModes?.find(findMode) || modes.find(findMode)
131-
}, [selectedModeTab, customModes, modes])
133+
}, [mode, customModes, modes])
132134

133135
// Helper function to safely access mode properties
134136
const getModeProperty = <T extends keyof ModeConfig>(
@@ -154,11 +156,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
154156
}
155157
}, [isCreateModeDialogOpen])
156158

157-
// Keep selected tab in sync with actual mode
158-
useEffect(() => {
159-
setSelectedModeTab(mode)
160-
}, [mode])
161-
162159
// Helper function to generate a unique slug from a name
163160
const generateSlug = useCallback((name: string, attempt = 0): string => {
164161
const baseSlug = name
@@ -188,6 +185,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
188185
groups: newModeGroups,
189186
}
190187
updateCustomMode(newModeSlug, newMode)
188+
switchMode(newModeSlug)
191189
setIsCreateModeDialogOpen(false)
192190
setNewModeName("")
193191
setNewModeSlug("")
@@ -478,7 +476,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
478476
padding: "4px 0",
479477
}}>
480478
{modes.map((modeConfig) => {
481-
const isActive = selectedModeTab === modeConfig.slug
479+
const isActive = mode === modeConfig.slug
482480
return (
483481
<button
484482
key={modeConfig.slug}
@@ -506,22 +504,20 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
506504

507505
<div style={{ marginBottom: "20px" }}>
508506
{/* Only show name and delete for custom modes */}
509-
{selectedModeTab && findModeBySlug(selectedModeTab, customModes) && (
507+
{mode && findModeBySlug(mode, customModes) && (
510508
<div style={{ display: "flex", gap: "12px", marginBottom: "16px" }}>
511509
<div style={{ flex: 1 }}>
512510
<div style={{ fontWeight: "bold", marginBottom: "4px" }}>Name</div>
513511
<div style={{ display: "flex", gap: "8px" }}>
514512
<VSCodeTextField
515-
value={
516-
getModeProperty(findModeBySlug(selectedModeTab, customModes), "name") ?? ""
517-
}
513+
value={getModeProperty(findModeBySlug(mode, customModes), "name") ?? ""}
518514
onChange={(e: Event | React.FormEvent<HTMLElement>) => {
519515
const target =
520516
(e as CustomEvent)?.detail?.target ||
521517
((e as any).target as HTMLInputElement)
522-
const customMode = findModeBySlug(selectedModeTab, customModes)
518+
const customMode = findModeBySlug(mode, customModes)
523519
if (customMode) {
524-
updateCustomMode(selectedModeTab, {
520+
updateCustomMode(mode, {
525521
...customMode,
526522
name: target.value,
527523
})
@@ -535,7 +531,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
535531
onClick={() => {
536532
vscode.postMessage({
537533
type: "deleteCustomMode",
538-
slug: selectedModeTab,
534+
slug: mode,
539535
})
540536
}}>
541537
<span className="codicon codicon-trash"></span>
@@ -553,7 +549,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
553549
marginBottom: "4px",
554550
}}>
555551
<div style={{ fontWeight: "bold" }}>Role Definition</div>
556-
{!findModeBySlug(selectedModeTab, customModes) && (
552+
{!findModeBySlug(mode, customModes) && (
557553
<VSCodeButton
558554
appearance="icon"
559555
onClick={() => {
@@ -579,28 +575,24 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
579575
</div>
580576
<VSCodeTextArea
581577
value={(() => {
582-
const customMode = findModeBySlug(selectedModeTab, customModes)
583-
const prompt = customModePrompts?.[selectedModeTab] as PromptComponent
584-
return (
585-
customMode?.roleDefinition ??
586-
prompt?.roleDefinition ??
587-
getRoleDefinition(selectedModeTab)
588-
)
578+
const customMode = findModeBySlug(mode, customModes)
579+
const prompt = customModePrompts?.[mode] as PromptComponent
580+
return customMode?.roleDefinition ?? prompt?.roleDefinition ?? getRoleDefinition(mode)
589581
})()}
590582
onChange={(e) => {
591583
const value =
592584
(e as CustomEvent)?.detail?.target?.value ||
593585
((e as any).target as HTMLTextAreaElement).value
594-
const customMode = findModeBySlug(selectedModeTab, customModes)
586+
const customMode = findModeBySlug(mode, customModes)
595587
if (customMode) {
596588
// For custom modes, update the JSON file
597-
updateCustomMode(selectedModeTab, {
589+
updateCustomMode(mode, {
598590
...customMode,
599591
roleDefinition: value.trim() || "",
600592
})
601593
} else {
602594
// For built-in modes, update the prompts
603-
updateAgentPrompt(selectedModeTab, {
595+
updateAgentPrompt(mode, {
604596
roleDefinition: value.trim() || undefined,
605597
})
606598
}
@@ -762,7 +754,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
762754
marginBottom: "4px",
763755
}}>
764756
<div style={{ fontWeight: "bold" }}>Mode-specific Custom Instructions</div>
765-
{!findModeBySlug(selectedModeTab, customModes) && (
757+
{!findModeBySlug(mode, customModes) && (
766758
<VSCodeButton
767759
appearance="icon"
768760
onClick={() => {
@@ -787,29 +779,29 @@ const PromptsView = ({ onDone }: PromptsViewProps) => {
787779
</div>
788780
<VSCodeTextArea
789781
value={(() => {
790-
const customMode = findModeBySlug(selectedModeTab, customModes)
791-
const prompt = customModePrompts?.[selectedModeTab] as PromptComponent
782+
const customMode = findModeBySlug(mode, customModes)
783+
const prompt = customModePrompts?.[mode] as PromptComponent
792784
return (
793785
customMode?.customInstructions ??
794786
prompt?.customInstructions ??
795-
getCustomInstructions(selectedModeTab, customModes)
787+
getCustomInstructions(mode, customModes)
796788
)
797789
})()}
798790
onChange={(e) => {
799791
const value =
800792
(e as CustomEvent)?.detail?.target?.value ||
801793
((e as any).target as HTMLTextAreaElement).value
802-
const customMode = findModeBySlug(selectedModeTab, customModes)
794+
const customMode = findModeBySlug(mode, customModes)
803795
if (customMode) {
804796
// For custom modes, update the JSON file
805-
updateCustomMode(selectedModeTab, {
797+
updateCustomMode(mode, {
806798
...customMode,
807799
customInstructions: value.trim() || undefined,
808800
})
809801
} else {
810802
// For built-in modes, update the prompts
811-
const existingPrompt = customModePrompts?.[selectedModeTab] as PromptComponent
812-
updateAgentPrompt(selectedModeTab, {
803+
const existingPrompt = customModePrompts?.[mode] as PromptComponent
804+
updateAgentPrompt(mode, {
813805
...existingPrompt,
814806
customInstructions: value.trim() || undefined,
815807
})

0 commit comments

Comments
 (0)