From 9c3176b29f93e9cd2e3e735654d5bc9f087b2f67 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:26:31 +0300 Subject: [PATCH] Preserve scroll position of the prompt manager --- public/scripts/PromptManager.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 806b5f308..dbf7dd4ed 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -685,6 +685,23 @@ class PromptManager { this.log('Initialized'); } + /** + * Get the scroll position of the prompt manager + * @returns {number} - Scroll position of the prompt manager + */ + #getScrollPosition() { + return document.getElementById(this.configuration.prefix + 'prompt_manager')?.closest('.scrollableInner')?.scrollTop; + } + + /** + * Set the scroll position of the prompt manager + * @param {number} scrollPosition - The scroll position to set + */ + #setScrollPosition(scrollPosition) { + if (scrollPosition === undefined || scrollPosition === null) return; + document.getElementById(this.configuration.prefix + 'prompt_manager')?.closest('.scrollableInner')?.scrollTo(0, scrollPosition); + } + /** * Main rendering function * @@ -703,17 +720,21 @@ class PromptManager { this.tryGenerate().finally(async () => { this.profileEnd('filling context'); this.profileStart('render'); + const scrollPosition = this.#getScrollPosition(); await this.renderPromptManager(); await this.renderPromptManagerListItems(); this.makeDraggable(); + this.#setScrollPosition(scrollPosition); this.profileEnd('render'); }); } else { // Executed during live communication this.profileStart('render'); + const scrollPosition = this.#getScrollPosition(); await this.renderPromptManager(); await this.renderPromptManagerListItems(); this.makeDraggable(); + this.#setScrollPosition(scrollPosition); this.profileEnd('render'); } }).catch(() => {