Preserve scroll position of the prompt manager

This commit is contained in:
Cohee 2024-06-12 00:26:31 +03:00
parent d69263923a
commit 9c3176b29f
1 changed files with 21 additions and 0 deletions

View File

@ -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(() => {