X-Git-Url: https://git.jacobcasper.com/?p=hnim.git;a=blobdiff_plain;f=hnim.js;h=7ac3f5d9ee704cdbee50f6829def5178fb51eb23;hp=593d56c45e69f3fdee8a1ce9acd1c3f33a1ece52;hb=e10798def56ccc77315816ca54e32e623cf49dd5;hpb=b9913766ace1452a8b6f6b3ac2d8810ba71147cc diff --git a/hnim.js b/hnim.js index 593d56c..7ac3f5d 100644 --- a/hnim.js +++ b/hnim.js @@ -15,7 +15,7 @@ const visible = (element) => { let bounds = element.getBoundingClientRect(); - return bounds.top >= 0 && bounds.bottom <= window.innerHeight; + return Math.abs(bounds.bottom - bounds.top) > window.innerHeight || (bounds.top >= 0 && bounds.bottom <= window.innerHeight); } const changeWithVisibleCallback = (comment, callback) => { @@ -25,7 +25,7 @@ selectedElement.style.outline = ''; selectedElement = comment; selectedElement.style.outline = '1px dashed black'; - if (!visible(comment)) { + while (!visible(comment)) { callback(); } } @@ -37,7 +37,7 @@ // Curry callback for moving downpage const changeDownpage = () => { - elementsIndex = Math.min(elementsIndex + 1, elements.length); + elementsIndex = Math.min(elementsIndex + 1, elements.length - 1); changeWithVisibleCallback(elements[elementsIndex], () => {window.scrollTo(0, window.scrollY + selectedElement.offsetHeight)}); } @@ -51,7 +51,7 @@ change(e.target.closest("tr.athing")); }) document.addEventListener("keydown", (e) => { - if (e.isComposing) { + if (e.target.type === 'textarea' || e.isComposing) { return; } switch (e.key) {