Confirm custom PM prompt deletion

a408328fc666b692858ddf1d3e460d4427027b82

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +22 -18Ignore whitespace
public/scripts/PromptManager.js+22 -18
@@ -1,12 +1,13 @@
11'use strict';
22
33import { callPopup, event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js';
44import { is_group_generating } from './group-chats.js';
55import { Message, TokenHandler } from './openai.js';
66import { power_user } from './power-user.js';
77import { debounce, waitUntilCondition, escapeHtml } from './utils.js';
88import { debounce_timeout } from './constants.js';
99import { renderTemplateAsync } from './templates.js';
10+import { Popup } from './popup.js';
1011
1112function debouncePromise(func, delay) {
1213 let timeoutId;
@@ -453,21 +454,24 @@ class PromptManager {
453454 };
454455
455456 // Delete selected prompt from list form and close edit form
456457 this.handleDeletePrompt = async (event) => {
457- const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;
458+ Popup.show.confirm('Are you sure you want to delete this prompt?', null).then((userChoice) => {
458- const prompt = this.getPromptById(promptID);
459+ if (!userChoice) return;
460+ const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;
461+ const prompt = this.getPromptById(promptID);
459462
460463 if (prompt && true === this.isPromptDeletionAllowed(prompt)) {
461464 const promptIndex = this.getPromptIndexById(promptID);
462465 this.serviceSettings.prompts.splice(Number(promptIndex), 1);
463466
464467 this.log('Deleted prompt: ' + prompt.identifier);
465468
466469 this.hidePopup();
467470 this.clearEditForm();
468471 this.render();
469472 this.saveServiceSettings();
470473 }
474+ });
471475 };
472476
473477 // Create new prompt, then save it to settings and close form.
@@ -527,9 +531,9 @@ class PromptManager {
527531
528532 // Import prompts for the selected character
529533 this.handleImport = () => {
530534 callPopupPopup.show.confirm('Existing prompts with the same ID will be overridden. Do you want to proceed?', 'confirm'null)
531535 .then(userChoice => {
532536 if (false === !userChoice) return;
533537
534538 const fileOpener = document.createElement('input');
535539 fileOpener.type = 'file';
@@ -563,9 +567,9 @@ class PromptManager {
563567
564568 // Restore default state of a characters prompt order
565569 this.handleCharacterReset = () => {
566570 callPopupPopup.show.confirm('This will reset the prompt order for this character. You will not lose any prompts.', 'confirm'null)
567571 .then(userChoice => {
568572 if (false === !userChoice) return;
569573
570574 this.removePromptOrderForCharacter(this.activeCharacter);
571575 this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder);
@@ -1538,7 +1542,7 @@ class PromptManager {
15381542 const encodedName = escapeHtml(prompt.name);
15391543 const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
15401544 const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides;
15411545 const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
15421546 const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
15431547 const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
15441548 const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);