mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add quick edit drawer and fields for main and jailbreak
This commit is contained in:
@ -300,6 +300,38 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
};
|
||||
|
||||
// Factory function for creating quick edit elements
|
||||
const saveSettings = this.saveServiceSettings;
|
||||
const createQuickEdit = function() {
|
||||
return {
|
||||
element: null,
|
||||
prompt: null,
|
||||
|
||||
from(element, prompt) {
|
||||
this.element = element;
|
||||
element.value = prompt.content ?? '';
|
||||
element.addEventListener('input', () => {
|
||||
prompt.content = element.value;
|
||||
saveSettings();
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
update(value) {
|
||||
this.element.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mainPrompt = this.getPromptById('main');
|
||||
const mainPromptTextarea = document.getElementById('main_prompt_quick_edit_textarea');
|
||||
const mainQuickEdit = createQuickEdit().from(mainPromptTextarea, mainPrompt);
|
||||
|
||||
const jailbreakPrompt = this.getPromptById('jailbreak');
|
||||
const jailbreakPromptTextarea = document.getElementById('jailbreak_prompt_quick_edit_textarea');
|
||||
const jailbreakQuickEdit = createQuickEdit().from(jailbreakPromptTextarea, jailbreakPrompt);
|
||||
|
||||
// Save prompt edit form to settings and close form.
|
||||
this.handleSavePrompt = (event) => {
|
||||
const promptId = event.target.dataset.pmPrompt;
|
||||
@ -313,6 +345,9 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
this.updatePromptWithPromptEditForm(prompt);
|
||||
}
|
||||
|
||||
if ('main' === promptId) mainQuickEdit.update(prompt.content)
|
||||
if ('jailbreak' === promptId) jailbreakQuickEdit.update(prompt.content)
|
||||
|
||||
this.log('Saved prompt: ' + promptId);
|
||||
|
||||
this.hidePopup();
|
||||
|
Reference in New Issue
Block a user