mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-01-05 00:01:01 +01:00
Remove fragile js from 9a58964834
This commit is contained in:
parent
3e24a127c7
commit
d1e9301a43
39
js/main.js
39
js/main.js
|
|
@ -1052,45 +1052,6 @@ new MutationObserver(() => addMiniDeletes()).observe(
|
|||
);
|
||||
addMiniDeletes();
|
||||
|
||||
//------------------------------------------------
|
||||
// Maintain distance from bottom when input height changes
|
||||
//------------------------------------------------
|
||||
let wasAtBottom = false;
|
||||
let preservedDistance = 0;
|
||||
|
||||
function checkIfAtBottom() {
|
||||
const distanceFromBottom = targetElement.scrollHeight - targetElement.scrollTop - targetElement.clientHeight;
|
||||
wasAtBottom = distanceFromBottom <= 1; // Allow for rounding errors
|
||||
}
|
||||
|
||||
function preserveScrollPosition() {
|
||||
preservedDistance = targetElement.scrollHeight - targetElement.scrollTop - targetElement.clientHeight;
|
||||
}
|
||||
|
||||
function restoreScrollPosition() {
|
||||
if (wasAtBottom) {
|
||||
// Force to bottom
|
||||
targetElement.scrollTop = targetElement.scrollHeight - targetElement.clientHeight;
|
||||
} else {
|
||||
// Restore original distance
|
||||
targetElement.scrollTop = targetElement.scrollHeight - targetElement.clientHeight - preservedDistance;
|
||||
}
|
||||
}
|
||||
|
||||
// Check position before input
|
||||
chatInput.addEventListener("beforeinput", () => {
|
||||
checkIfAtBottom();
|
||||
preserveScrollPosition();
|
||||
});
|
||||
|
||||
// Restore after input
|
||||
chatInput.addEventListener("input", () => {
|
||||
requestAnimationFrame(() => restoreScrollPosition());
|
||||
});
|
||||
|
||||
// Update wasAtBottom when user scrolls
|
||||
targetElement.addEventListener("scroll", checkIfAtBottom);
|
||||
|
||||
//------------------------------------------------
|
||||
// Fix autoscroll after fonts load
|
||||
//------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue