scroll: fix position saving

throttling wasn't working at all, should be debounce to get the last position
This commit is contained in:
Sören Weber 2025-02-17 08:31:53 +01:00
parent 0dd98363fb
commit 85824e217f
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 7 additions and 9 deletions
layouts/partials
static/js

View file

@ -1 +1 @@
7.3.2+de59e6700a230cecc75cebb1b225fe189f0189e7
7.3.2+0dd98363fbc04746c77cd13539a0d1b3f1a9de8e

View file

@ -62,14 +62,11 @@ function adjustContentWidth() {
elc.style[dir_padding_end] = '' + end + 'px';
}
function throttle(func, limit) {
let inThrottle;
let debounceTimeout;
function debounce(func, delay) {
return function (...args) {
if (!inThrottle) {
func.apply(this, args);
inThrottle = true;
setTimeout(() => (inThrottle = false), limit);
}
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => func.apply(this, args), delay);
};
}
@ -1327,6 +1324,7 @@ function initScrollPositionSaver() {
function savePosition(event) {
// #959 if we fiddle around with the history during print preview
// GC will close the preview immediatley
console.log('savePosition', event);
if (isPrintPreview) {
return;
}
@ -1341,7 +1339,7 @@ function initScrollPositionSaver() {
if (!ticking) {
window.requestAnimationFrame(function () {
// #996 GC is so damn slow that we need further throttling
throttle(savePosition, 250);
debounce(savePosition, 200)();
ticking = false;
});
ticking = true;