Skip to content

Commit ce64978

Browse files
committed
feat(mode): auto select imported mode
1 parent 97f9686 commit ce64978

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

src/core/config/CustomModesManager.ts

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

4647
export class CustomModesManager {
@@ -953,6 +954,8 @@ export class CustomModesManager {
953954
}
954955
}
955956

957+
const importedSlugs: string[] = []
958+
956959
// Process each mode in the import
957960
for (const importMode of importData.customModes) {
958961
const { rulesFiles, ...modeConfig } = importMode
@@ -984,12 +987,14 @@ export class CustomModesManager {
984987

985988
// Import rules files (this also handles cleanup of existing rules folders)
986989
await this.importRulesFiles(importMode, rulesFiles || [], source)
990+
991+
importedSlugs.push(importMode.slug)
987992
}
988993

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

992-
return { success: true }
997+
return { success: true, importedSlugs }
993998
} catch (error) {
994999
const errorMessage = error instanceof Error ? error.message : String(error)
9951000
logger.error("Failed to import mode with rules", { error: errorMessage })

src/core/config/__tests__/CustomModesManager.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ describe("CustomModesManager", () => {
870870
const result = await manager.importModeWithRules(importYaml)
871871

872872
expect(result.success).toBe(true)
873+
expect(result.importedSlugs).toEqual(["imported-mode"])
873874
expect(fs.writeFile).toHaveBeenCalledWith(
874875
expect.stringContaining(".roomodes"),
875876
expect.stringContaining("imported-mode"),
@@ -991,6 +992,7 @@ describe("CustomModesManager", () => {
991992
const result = await manager.importModeWithRules(importYaml)
992993

993994
expect(result.success).toBe(true)
995+
expect(result.importedSlugs).toEqual(["mode1", "mode2"])
994996
expect(roomodesContent.customModes).toHaveLength(2)
995997
expect(roomodesContent.customModes[0].slug).toBe("mode1")
996998
expect(roomodesContent.customModes[1].slug).toBe("mode2")

src/core/webview/webviewMessageHandler.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,12 +2220,20 @@ export const webviewMessageHandler = async (
22202220
// Update state after importing
22212221
const customModes = await provider.customModesManager.getCustomModes()
22222222
await updateGlobalState("customModes", customModes)
2223+
2224+
// Switch to the first imported mode if available
2225+
if (result.importedSlugs && result.importedSlugs.length > 0) {
2226+
const firstImportedSlug = result.importedSlugs[0]
2227+
await updateGlobalState("mode", firstImportedSlug)
2228+
}
2229+
22232230
await provider.postStateToWebview()
22242231

2225-
// Send success message to webview
2232+
// Send success message to webview with the imported slug
22262233
provider.postMessageToWebview({
22272234
type: "importModeResult",
22282235
success: true,
2236+
importedSlug: result.importedSlugs?.[0],
22292237
})
22302238

22312239
// Show success message

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export interface ExtensionMessage {
179179
customMode?: ModeConfig
180180
slug?: string
181181
success?: boolean
182+
importedSlug?: string
182183
values?: Record<string, any>
183184
requestId?: string
184185
promptText?: string

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ const ModesView = ({ onDone }: ModesViewProps) => {
465465
if (message.error !== "cancelled") {
466466
console.error("Failed to import mode:", message.error)
467467
}
468+
} else if (message.importedSlug) {
469+
// Switch to the imported mode
470+
setVisualMode(message.importedSlug)
468471
}
469472
} else if (message.type === "checkRulesDirectoryResult") {
470473
setHasRulesToExport((prev) => ({

0 commit comments

Comments
 (0)