diff --git a/webview-ui/src/components/prompts/PromptsView.tsx b/webview-ui/src/components/prompts/PromptsView.tsx index b9b4127cdd..461100cb9f 100644 --- a/webview-ui/src/components/prompts/PromptsView.tsx +++ b/webview-ui/src/components/prompts/PromptsView.tsx @@ -65,6 +65,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { const [isToolsEditMode, setIsToolsEditMode] = useState(false) const [isCreateModeDialogOpen, setIsCreateModeDialogOpen] = useState(false) const [activeSupportTab, setActiveSupportTab] = useState("ENHANCE") + const [selectedModeTab, setSelectedModeTab] = useState(mode) // Direct update functions const updateAgentPrompt = useCallback( @@ -110,26 +111,23 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { text: slug, }) }, []) - - // Handle mode switching with explicit state initialization + // Handle mode tab selection without actually switching modes const handleModeSwitch = useCallback( (modeConfig: ModeConfig) => { - if (modeConfig.slug === mode) return // Prevent unnecessary updates + if (modeConfig.slug === selectedModeTab) return // Prevent unnecessary updates - // First switch the mode - switchMode(modeConfig.slug) - - // Exit tools edit mode when switching modes + // Update selected tab and reset tools edit mode + setSelectedModeTab(modeConfig.slug) setIsToolsEditMode(false) }, - [mode, switchMode, setIsToolsEditMode], + [selectedModeTab, setIsToolsEditMode], ) // Helper function to get current mode's config const getCurrentMode = useCallback((): ModeConfig | undefined => { - const findMode = (m: ModeConfig): boolean => m.slug === mode + const findMode = (m: ModeConfig): boolean => m.slug === selectedModeTab return customModes?.find(findMode) || modes.find(findMode) - }, [mode, customModes, modes]) + }, [selectedModeTab, customModes, modes]) // Helper function to safely access mode properties const getModeProperty = ( @@ -155,6 +153,11 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { } }, [isCreateModeDialogOpen]) + // Keep selected tab in sync with actual mode + useEffect(() => { + setSelectedModeTab(mode) + }, [mode]) + // Helper function to generate a unique slug from a name const generateSlug = useCallback((name: string, attempt = 0): string => { const baseSlug = name @@ -184,7 +187,6 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { groups: newModeGroups, } updateCustomMode(newModeSlug, newMode) - switchMode(newModeSlug) setIsCreateModeDialogOpen(false) setNewModeName("") setNewModeSlug("") @@ -479,7 +481,7 @@ const PromptsView = ({ onDone }: PromptsViewProps) => { padding: "4px 0", }}> {modes.map((modeConfig) => { - const isActive = mode === modeConfig.slug + const isActive = selectedModeTab === modeConfig.slug return (