Skip to content
Merged
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
12 changes: 8 additions & 4 deletions src/core/config/CustomModesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,13 @@ export class CustomModesManager {
// Validate the mode configuration before saving
const validationResult = modeConfigSchema.safeParse(config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend validation implementation looks solid! Using modeConfigSchema.safeParse() with proper error handling and user-friendly messages is exactly what we need. At least I got something right.

if (!validationResult.success) {
const errors = validationResult.error.errors.map((e) => e.message).join(", ")
logger.error(`Invalid mode configuration for ${slug}`, { errors: validationResult.error.errors })
throw new Error(`Invalid mode configuration: ${errors}`)
const errorMessages = validationResult.error.errors
.map((err) => `${err.path.join(".")}: ${err.message}`)
.join(", ")
const errorMessage = `Invalid mode configuration: ${errorMessages}`
logger.error("Mode validation failed", { slug, errors: validationResult.error.errors })
vscode.window.showErrorMessage(t("common:customModes.errors.updateFailed", { error: errorMessage }))
return
}

const isProjectMode = config.source === "project"
Expand Down Expand Up @@ -786,7 +790,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
22 changes: 15 additions & 7 deletions webview-ui/src/components/modes/ModesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -755,17 +755,25 @@ const ModesView = ({ onDone }: ModesViewProps) => {
}
}}
onChange={(e) => {
setLocalModeName(e.target.value)
const newName = e.target.value
// Allow users to type freely, including emptying the field
setLocalModeName(newName)
}}
onBlur={() => {
const customMode = findModeBySlug(visualMode, customModes)
if (customMode && localModeName.trim()) {
if (customMode) {
const trimmedName = localModeName.trim()
// Only update if the name is not empty
updateCustomMode(visualMode, {
...customMode,
name: localModeName,
source: customMode.source || "global",
})
if (trimmedName) {
updateCustomMode(visualMode, {
...customMode,
name: trimmedName,
source: customMode.source || "global",
})
} else {
// Revert to the original name if empty
setLocalModeName(customMode.name)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned adding an onBlur handler in the PR description to restore the original name if the field is left empty, but I seem to have forgotten to actually implement it. Is this intentional, or did I just forget?

The onBlur handler would restore the original value if the user leaves the field empty, providing better UX while still preventing invalid saves.

// Clear the editing state
setCurrentEditingModeSlug(null)
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/src/vite-plugins/sourcemapPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export function sourcemapPlugin(): Plugin {
})
}

// Write back the updated source map
fs.writeFileSync(mapPath, JSON.stringify(mapContent))
// Write back the updated source map with proper formatting
fs.writeFileSync(mapPath, JSON.stringify(mapContent, null, 2))
console.log(`Updated source map for ${jsFile}`)
} catch (error) {
console.error(`Error processing source map for ${jsFile}:`, error)
Expand Down
Loading