Skip to content

Commit a76b089

Browse files
committed
feat: automatically switch to imported mode after successful import
- Add importedModes field to ImportResult interface to track imported mode slugs - Modify importModeWithRules method to collect and return imported mode slugs - Update webview message handler to automatically switch to first imported mode - Update ModesView.tsx to handle successful import with mode switching Fixes #6491
1 parent 74672fa commit a76b089

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface ExportResult {
4141
interface ImportResult {
4242
success: boolean
4343
error?: string
44+
importedModes?: string[]
4445
}
4546

4647
export class CustomModesManager {
@@ -786,7 +787,7 @@ export class CustomModesManager {
786787
// This excludes the rules-{slug} folder from the path
787788
const relativePath = path.relative(modeRulesDir, filePath)
788789
// Normalize path to use forward slashes for cross-platform compatibility
789-
const normalizedRelativePath = relativePath.replace(/\\/g, '/')
790+
const normalizedRelativePath = relativePath.replace(/\\/g, "/")
790791
rulesFiles.push({ relativePath: normalizedRelativePath, content: content.trim() })
791792
}
792793
}
@@ -949,6 +950,9 @@ export class CustomModesManager {
949950
}
950951
}
951952

953+
// Track imported mode slugs
954+
const importedModes: string[] = []
955+
952956
// Process each mode in the import
953957
for (const importMode of importData.customModes) {
954958
const { rulesFiles, ...modeConfig } = importMode
@@ -980,12 +984,15 @@ export class CustomModesManager {
980984

981985
// Import rules files (this also handles cleanup of existing rules folders)
982986
await this.importRulesFiles(importMode, rulesFiles || [], source)
987+
988+
// Track the imported mode slug
989+
importedModes.push(importMode.slug)
983990
}
984991

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

988-
return { success: true }
995+
return { success: true, importedModes }
989996
} catch (error) {
990997
const errorMessage = error instanceof Error ? error.message : String(error)
991998
logger.error("Failed to import mode with rules", { error: errorMessage })

src/core/webview/webviewMessageHandler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,14 @@ export const webviewMessageHandler = async (
18761876
// Update state after importing
18771877
const customModes = await provider.customModesManager.getCustomModes()
18781878
await updateGlobalState("customModes", customModes)
1879+
1880+
// Automatically switch to imported mode if modes were imported
1881+
if (result.importedModes && result.importedModes.length > 0) {
1882+
// Switch to the first imported mode
1883+
const modeToSwitchTo = result.importedModes[0]
1884+
await updateGlobalState("mode", modeToSwitchTo)
1885+
}
1886+
18791887
await provider.postStateToWebview()
18801888

18811889
// Send success message to webview

webview-ui/src/components/modes/ModesView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,10 @@ const ModesView = ({ onDone }: ModesViewProps) => {
460460
setIsImporting(false)
461461
setShowImportDialog(false)
462462

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

0 commit comments

Comments
 (0)