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