Prevent similarily-ish preset renames

Adds validation to prevent renaming presets to names that are identical when ignoring case and accents
Avoids accidental duplicates by ensuring meaningful name changes during preset renames
This commit is contained in:
Wolfsblvt
2025-04-08 21:14:09 +02:00
parent 6895892d5a
commit 55ed5b325c

View File

@@ -36,7 +36,7 @@ import {
textgenerationwebui_presets,
textgenerationwebui_settings as textgen_settings,
} from './textgen-settings.js';
import { download, parseJsonFile, waitUntilCondition } from './utils.js';
import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js';
import { t } from './i18n.js';
import { reasoning_templates } from './reasoning.js';
@@ -454,6 +454,9 @@ class PresetManager {
async renamePreset(newName) {
const oldName = this.getSelectedPresetName();
if (equalsIgnoreCaseAndAccents(oldName, newName)) {
throw new Error('New name must be different from old name');
}
try {
await this.savePreset(newName);
await this.deletePreset(oldName);
@@ -892,6 +895,10 @@ export async function initPresetManager() {
console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled');
return;
}
if (equalsIgnoreCaseAndAccents(oldName, newName)) {
console.warn('Preset name is the same (ignoring case and accents)');
return;
}
await presetManager.renamePreset(newName);