From 489bc7a50bc9b795513bb95bb810abd5bf73f238 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 25 Feb 2015 19:01:40 +0000 Subject: [PATCH] Only scroll to top when tiddlers are completely off-screen Fixes #1526 --- core/modules/utils/dom/scroller.js | 12 ++++++++---- editions/prerelease/tiddlers/view.tid | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/modules/utils/dom/scroller.js b/core/modules/utils/dom/scroller.js index 1b1ca82b8..d08207629 100644 --- a/core/modules/utils/dom/scroller.js +++ b/core/modules/utils/dom/scroller.js @@ -68,15 +68,19 @@ PageScroller.prototype.scrollIntoView = function(element) { height: clientBounds.height }; // We'll consider the horizontal and vertical scroll directions separately via this function + // targetPos/targetSize - position and size of the target element + // currentPos/currentSize - position and size of the current scroll viewport + // returns: new position of the scroll viewport var getEndPos = function(targetPos,targetSize,currentPos,currentSize) { - // If the target is above/left of the current view, then scroll to it's top/left - if(targetPos <= currentPos) { +console.log("getEndPos",targetPos,targetSize,currentPos,currentSize) + // If the target is entirely above/left of the current view, then scroll to its top/left + if((targetPos + targetSize) <= currentPos) { return targetPos; // If the target is smaller than the window and the scroll position is too far up, then scroll till the target is at the bottom of the window } else if(targetSize < currentSize && currentPos < (targetPos + targetSize - currentSize)) { return targetPos + targetSize - currentSize; - // If the target is big, then just scroll to the top - } else if(currentPos < targetPos) { + // If the target is out of view below/right, then just scroll to the top/left + } else if(targetPos > (currentPos + currentSize)) { return targetPos; // Otherwise, stay where we are } else { diff --git a/editions/prerelease/tiddlers/view.tid b/editions/prerelease/tiddlers/view.tid index 0e45ea308..13fe4c5ff 100644 --- a/editions/prerelease/tiddlers/view.tid +++ b/editions/prerelease/tiddlers/view.tid @@ -1,3 +1,3 @@ title: $:/view -stacked \ No newline at end of file +classic \ No newline at end of file