From dc6543719c68f87ab624203629320f6b5e99b947 Mon Sep 17 00:00:00 2001 From: glacambre Date: Wed, 11 Apr 2018 08:23:11 +0200 Subject: [PATCH] excmds.ts: Make scrollline recursive, fix recursiveScroll --- src/excmds.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/excmds.ts b/src/excmds.ts index f63c1ef9..2da07896 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -243,14 +243,25 @@ function recursiveScroll(x: number, y: number, nodes: Element[]) { let top = rect.top node.scrollBy(x, y); if (top == node.getClientRects()[0].top) { - let children = Array.prototype.slice.call(node.children).filter(DOM.isVisible) + // children used to be .filter(DOM.isVisible)'d but apparently nodes + // that are !DOM.isVisible can have children that are DOM.isVisible + let children = Array.prototype.slice.call(node.childNodes) recursiveScroll(x, y, nodes.concat(children)) } } //#content export function scrollline(n = 1) { + let top = document.body.getClientRects()[0].top window.scrollByLines(n) + if (top == document.body.getClientRects()[0].top) { + const cssHeight = window.getComputedStyle(document.body).getPropertyValue('line-height') + // Remove the "px" at the end + const lineHeight = parseInt(cssHeight.substr(0, cssHeight.length - 2)) + // lineHeight probably can't be NaN but let's make sure + if (lineHeight) + recursiveScroll(0, lineHeight * n, [window.document.body]) + } } //#content