mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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:
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user