X-Git-Url: https://git.jacobcasper.com/?p=hnim.git;a=blobdiff_plain;f=hnim.js;h=1e804b37762f0f57bdf47f24ac2c6bad3d897421;hp=890852d9bf9b984b0ee82c4a7a1f983bf0bf36fc;hb=85e14fb2bd08b90750d2048674f102d34a189f28;hpb=93b766f9a4c9db36f1c899cc02c4caa24af995dc diff --git a/hnim.js b/hnim.js index 890852d..1e804b3 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) => { @@ -32,12 +32,12 @@ const change = (comment) => { elementsIndex = elements.indexOf(comment); - changeWithVisibleCallback(comment, () => {}); + changeWithVisibleCallback(comment, () => {comment.scrollIntoView()}); } // 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) {