Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/core/config/CustomModesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface ExportResult {
interface ImportResult {
success: boolean
error?: string
importedModes?: string[]
}

export class CustomModesManager {
Expand Down Expand Up @@ -786,7 +787,7 @@ export class CustomModesManager {
// This excludes the rules-{slug} folder from the path
const relativePath = path.relative(modeRulesDir, filePath)
// Normalize path to use forward slashes for cross-platform compatibility
const normalizedRelativePath = relativePath.replace(/\\/g, '/')
const normalizedRelativePath = relativePath.replace(/\\/g, "/")
rulesFiles.push({ relativePath: normalizedRelativePath, content: content.trim() })
}
}
Expand Down Expand Up @@ -949,6 +950,9 @@ export class CustomModesManager {
}
}

// Track imported mode slugs
const importedModes: string[] = []

// Process each mode in the import
for (const importMode of importData.customModes) {
const { rulesFiles, ...modeConfig } = importMode
Expand Down Expand Up @@ -980,12 +984,15 @@ export class CustomModesManager {

// Import rules files (this also handles cleanup of existing rules folders)
await this.importRulesFiles(importMode, rulesFiles || [], source)

// Track the imported mode slug
importedModes.push(importMode.slug)
}

// Refresh the modes after import
await this.refreshMergedState()

return { success: true }
return { success: true, importedModes }
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
logger.error("Failed to import mode with rules", { error: errorMessage })
Expand Down
8 changes: 8 additions & 0 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,14 @@ export const webviewMessageHandler = async (
// Update state after importing
const customModes = await provider.customModesManager.getCustomModes()
await updateGlobalState("customModes", customModes)

// Automatically switch to imported mode if modes were imported
if (result.importedModes && result.importedModes.length > 0) {
// Switch to the first imported mode
const modeToSwitchTo = result.importedModes[0]
await updateGlobalState("mode", modeToSwitchTo)
}

await provider.postStateToWebview()

// Send success message to webview
Expand Down
5 changes: 4 additions & 1 deletion webview-ui/src/components/modes/ModesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ const ModesView = ({ onDone }: ModesViewProps) => {
setIsImporting(false)
setShowImportDialog(false)

if (!message.success) {
if (message.success) {
// The backend has already switched the mode, so we just need to update the visual state
// The mode change will be reflected in the next state update from the backend
} else {
// Only log error if it's not a cancellation
if (message.error !== "cancelled") {
console.error("Failed to import mode:", message.error)
Expand Down
Loading