From 3df341621d30b205775288e324cef137c48e9f6e Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 20 Feb 2015 20:04:18 +0000 Subject: [PATCH] Alternative fix for unnecessary startup scrolling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @aelocson here’s an alternative fix for #981, as discussed in https://github.com/Jermolene/TiddlyWiki5/commit/691e5719a4ff74a04d389bd1 26ba2a69e7651a2a#commitcomment-9848682 It does seem a lot nicer. It avoids the problem you raised, and also avoids scrolling when a permalink is used. I suspect that we’d need to make the hard-coded 50 pixels be configurable. --- core/modules/startup/story.js | 2 ++ core/modules/utils/dom/scroller.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/modules/startup/story.js b/core/modules/startup/story.js index b8a92bc58..ec0202c1f 100644 --- a/core/modules/startup/story.js +++ b/core/modules/startup/story.js @@ -133,6 +133,8 @@ function openStartupTiddlers(options) { target = target.substr(2,target.length - 4); } $tw.wiki.addToHistory(target); + } else if(storyList.length > 0) { + $tw.wiki.addToHistory(storyList[0]); } } diff --git a/core/modules/utils/dom/scroller.js b/core/modules/utils/dom/scroller.js index 786c54321..1b1ca82b8 100644 --- a/core/modules/utils/dom/scroller.js +++ b/core/modules/utils/dom/scroller.js @@ -85,8 +85,8 @@ PageScroller.prototype.scrollIntoView = function(element) { }, endX = getEndPos(bounds.left,bounds.width,scrollPosition.x,window.innerWidth), endY = getEndPos(bounds.top,bounds.height,scrollPosition.y,window.innerHeight); - // Only scroll if necessary - if(endX !== scrollPosition.x || endY !== scrollPosition.y) { + // Only scroll if the position has changed, plus a special case that we won't scroll less than 50 pixels from the top of the window + if((endX !== scrollPosition.x || endY !== scrollPosition.y) && (scrollPosition.y !== 0 || endY > 50)) { var self = this, drawFrame; drawFrame = function () {