From 01cb95fba8ef604d681d3c02b5c996cb241275ff Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 19 Aug 2023 22:03:10 +0300 Subject: [PATCH] Save and restore quick edit heights --- public/scripts/PromptManager.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 29d71e28e..06517c8c9 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -1306,14 +1306,46 @@ PromptManagerModule.prototype.renderPromptManager = function () { rangeBlockDiv.querySelector('.export-promptmanager-prompts-character')?.addEventListener('click', this.handleCharacterExport); const quickEditContainer = document.getElementById('quick-edit-container'); + const heights = this.saveTextAreaHeights(quickEditContainer); quickEditContainer.innerHTML = ''; this.createQuickEdit('jailbreak', 'Jailbreak'); this.createQuickEdit('nsfw', 'NSFW'); this.createQuickEdit('main', 'Main'); + + this.restoreTextAreaHeights(quickEditContainer, heights); } }; +/** + * Restores the height of each textarea in the container + * @param container The container to search for textareas + * @param heights An object with textarea ids as keys and heights as values + */ +PromptManagerModule.prototype.restoreTextAreaHeights = function(container, heights) { + if (Object.keys(heights).length === 0) return; + + $(container).find('textarea').each(function () { + const height = heights[this.id]; + if (height > 0) $(this).height(height); + }); +} + +/** + * Saves the current height of each textarea in the container + * @param container The container to search for textareas + * @returns {{}} An object with textarea ids as keys and heights as values + */ +PromptManagerModule.prototype.saveTextAreaHeights = function(container) { + const heights = {}; + + $(container).find('textarea').each(function () { + heights[this.id] = $(this).height(); + }); + + return heights; +} + /** * Empties, then re-assembles the prompt list */