From 6eb28b6b4f177ab5a680e6628f919842df7561fe Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 14 Jan 2015 16:24:55 -0800 Subject: [PATCH] more scrolling fixes. --- lib/widget.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 180c4d8..9d118a4 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1436,25 +1436,14 @@ Screen.prototype._focus = function(self, old) { // If we're in a scrollable element, // automatically scroll to the focused element. if (el) { - var ryi = self.top - el.top - el.itop - , ryl = self.top + self.height - el.top - el.ibottom - , visible = el.height - el.iheight; - - if (ryi < el.childBase) { - el.scrollTo(ryi); - self.screen.render(); - } else if (self.rtop + self.height > el.childBase + el.height - el.iheight) { - //} else if (self.rtop + self.height > el.childBase + el.height) { + var visible = self.screen.height - el.top - el.itop - el.bottom - el.ibottom; + if (self.rtop < el.childBase) { el.scrollTo(self.rtop); - //el.scrollTo(self.rtop + self.height - el.height); + self.screen.render(); + } else if (self.rtop + self.height - self.ibottom > el.childBase + visible) { + el.scrollTo(self.rtop - (visible - self.height)); + self.screen.render(); } - //} else if (ryi >= el.childBase + visible) { - // el.scrollTo(ryi + self.height); - // self.screen.render(); - //} else if (ryl >= el.childBase + visible) { - // el.scrollTo(ryi + self.height); - // self.screen.render(); - //} } if (old) { @@ -3848,7 +3837,7 @@ ScrollableBox.prototype.setScroll = ScrollableBox.prototype.scrollTo = function(offset) { // XXX // At first, this appeared to account for the first new calculation of childBase: - // this.scroll(0); + this.scroll(0); return this.scroll(offset - (this.childBase + this.childOffset)); };