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