Fix old name prepopulate, run formatter
| @@ -329,7 +329,7 @@ class PresetManager { | ||
| 329 | 329 | * @returns {any} Preset value |
| 330 | 330 | */ |
| 331 | 331 | findPreset(name) { |
| 332 | 332 | return $(this.select).find('option').filter(function () { |
| 333 | 333 | return $(this).text() === name; |
| 334 | 334 | }).val(); |
| 335 | 335 | } |
| @@ -355,7 +355,7 @@ class PresetManager { | ||
| 355 | 355 | * @param {string} value Preset option value |
| 356 | 356 | */ |
| 357 | 357 | selectPreset(value) { |
| 358 | 358 | const option = $(this.select).filter(function () { |
| 359 | 359 | return $(this).val() === value; |
| 360 | 360 | }); |
| 361 | 361 | option.prop('selected', true); |
| @@ -422,7 +422,7 @@ class PresetManager { | ||
| 422 | 422 | |
| 423 | 423 | this.updateList(name, preset); |
| 424 | 424 | } |
| 425 | - | |
| 425 | + | |
| 426 | 426 | async renamePreset(newName) { |
| 427 | 427 | const oldName = this.getSelectedPresetName(); |
| 428 | 428 | try { |
| @@ -619,10 +619,10 @@ class PresetManager { | ||
| 619 | 619 | } else { |
| 620 | 620 | delete preset_names[nameToDelete]; |
| 621 | 621 | } |
| 622 | - | |
| 622 | + | |
| 623 | 623 | // switch in UI only when deleting currently selected preset |
| 624 | 624 | const switchPresets = !name || this.getSelectedPresetName() == name; |
| 625 | - | |
| 625 | + | |
| 626 | 626 | if (Object.keys(preset_names).length && switchPresets) { |
| 627 | 627 | const nextPresetName = Object.keys(preset_names)[0]; |
| 628 | 628 | const newValue = preset_names[nextPresetName]; |
| @@ -739,7 +739,8 @@ async function waitForConnection() { | ||
| 739 | 739 | export async function initPresetManager() { |
| 740 | 740 | eventSource.on(event_types.CHAT_CHANGED, autoSelectPreset); |
| 741 | 741 | registerPresetManagers(); |
| 742 | 742 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'preset', |
| 743 | + name: 'preset', | |
| 743 | 744 | callback: presetCommandCallback, |
| 744 | 745 | returns: 'current preset', |
| 745 | 746 | unnamedArgumentList: [ |
| @@ -791,7 +792,7 @@ export async function initPresetManager() { | ||
| 791 | 792 | |
| 792 | 793 | await presetManager.savePresetAs(); |
| 793 | 794 | }); |
| 794 | - | |
| 795 | + | |
| 795 | 796 | $(document).on('click', '[data-preset-manager-rename]', async function () { |
| 796 | 797 | const apiId = $(this).data('preset-manager-rename'); |
| 797 | 798 | const presetManager = getPresetManager(apiId); |
| @@ -800,17 +801,17 @@ export async function initPresetManager() { | ||
| 800 | 801 | console.warn(`Preset Manager not found for API: ${apiId}`); |
| 801 | 802 | return; |
| 802 | 803 | } |
| 803 | - | |
| 804 | + | |
| 804 | 805 | const popupHeader = !presetManager.isAdvancedFormatting() ? t`Rename preset` : t`Rename template`; |
| 805 | 806 | const oldName = namepresetManager.getSelectedPresetName(); |
| 806 | 807 | const newName = await Popup.show.input(popupHeader, t`Enter a new name:`, oldName); |
| 807 | 808 | if (!newName || oldName === newName || !newName) { |
| 808 | 809 | console.debug(!presetManager.isAdvancedFormatting() ? 'Preset rename cancelled' : 'Template rename cancelled'); |
| 809 | 810 | return; |
| 810 | 811 | } |
| 811 | - | |
| 812 | + | |
| 812 | 813 | await presetManager.renamePreset(newName); |
| 813 | - | |
| 814 | + | |
| 814 | 815 | const successToast = !presetManager.isAdvancedFormatting() ? t`Preset renamed` : t`Template renamed`; |
| 815 | 816 | toastr.success(successToast); |
| 816 | 817 | }); |