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
| @@ -36,7 +36,7 @@ import { | ||
| 36 | 36 | textgenerationwebui_presets, |
| 37 | 37 | textgenerationwebui_settings as textgen_settings, |
| 38 | 38 | } from './textgen-settings.js'; |
| 39 | 39 | import { download, equalsIgnoreCaseAndAccents, parseJsonFile, waitUntilCondition } from './utils.js'; |
| 40 | 40 | import { t } from './i18n.js'; |
| 41 | 41 | import { reasoning_templates } from './reasoning.js'; |
| 42 | 42 | |
| @@ -454,6 +454,9 @@ class PresetManager { | ||
| 454 | 454 | |
| 455 | 455 | async renamePreset(newName) { |
| 456 | 456 | const oldName = this.getSelectedPresetName(); |
| 457 | + if (equalsIgnoreCaseAndAccents(oldName, newName)) { | |
| 458 | + throw new Error('New name must be different from old name'); | |
| 459 | + } | |
| 457 | 460 | try { |
| 458 | 461 | await this.savePreset(newName); |
| 459 | 462 | await this.deletePreset(oldName); |
| @@ -892,6 +895,10 @@ export async function initPresetManager() { | ||
| 892 | 895 | console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled'); |
| 893 | 896 | return; |
| 894 | 897 | } |
| 898 | + if (equalsIgnoreCaseAndAccents(oldName, newName)) { | |
| 899 | + console.warn('Preset name is the same (ignoring case and accents)'); | |
| 900 | + return; | |
| 901 | + } | |
| 895 | 902 | |
| 896 | 903 | await presetManager.renamePreset(newName); |
| 897 | 904 | |