fixup 362d9444: never scroll manage page on toggling a visible entry

This commit is contained in:
tophf 2017-11-30 00:54:40 +03:00
parent e6109d509b
commit 6f0dd5e9b6
2 changed files with 7 additions and 7 deletions

View File

@ -89,14 +89,14 @@ function onDOMready() {
} }
function scrollElementIntoView(element) { function scrollElementIntoView(element, {invalidMarginRatio = .25} = {}) {
// align to the top/bottom of the visible area if wasn't visible // align to the top/bottom of the visible area if wasn't visible
const bounds = element.getBoundingClientRect(); const {top, height} = element.getBoundingClientRect();
const boundsContainer = element.parentNode.getBoundingClientRect(); const {top: parentTop, bottom: parentBottom} = element.parentNode.getBoundingClientRect();
const windowHeight = window.innerHeight; const windowHeight = window.innerHeight;
if (bounds.top < Math.max(boundsContainer.top, windowHeight / 4) || if (top < Math.max(parentTop, windowHeight * invalidMarginRatio) ||
bounds.top > Math.min(boundsContainer.bottom, windowHeight) - bounds.height - windowHeight / 4) { top > Math.min(parentBottom, windowHeight) - height - windowHeight * invalidMarginRatio) {
window.scrollBy(0, bounds.top - windowHeight / 2 + bounds.height); window.scrollBy(0, top - windowHeight / 2 + height);
} }
} }

View File

@ -406,7 +406,7 @@ function handleUpdate(style, {reason, method} = {}) {
filterAndAppend({entry}); filterAndAppend({entry});
if (!entry.matches('.hidden') && reason !== 'import') { if (!entry.matches('.hidden') && reason !== 'import') {
animateElement(entry); animateElement(entry);
scrollElementIntoView(entry); scrollElementIntoView(entry, {invalidMarginRatio: 0});
} }
function handleToggledOrCodeOnly() { function handleToggledOrCodeOnly() {