From bdff4561d4e2b0163d3db6206de772a43c3619b0 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Wed, 8 Jan 2020 15:37:13 +1000 Subject: [PATCH] FIX: Make scrolling to bottom post in topic more consistent (#8671) * Make scrolling to bottom post in topic more consistent * when using the slider to scroll past the bottom post, we now scroll to the bottom of the post/page IF the post height is > the window height (e.g. really long posts). if the post height is smaller, then we lock onto and jump to the top of the post * this also removes the mobile hack that would always jump to the top of the last post on mobile * Prettier lint --- app/assets/javascripts/discourse/lib/url.js.es6 | 15 ++++++++++++--- .../discourse/widgets/topic-timeline.js.es6 | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/url.js.es6 b/app/assets/javascripts/discourse/lib/url.js.es6 index ae252facf8..bb5d8d31a0 100644 --- a/app/assets/javascripts/discourse/lib/url.js.es6 +++ b/app/assets/javascripts/discourse/lib/url.js.es6 @@ -99,9 +99,18 @@ const DiscourseURL = EmberObject.extend({ let holder; if (opts.jumpEnd) { - $(window).scrollTop($(document).height() - $(window).height()); - _transitioning = false; - return; + let $holder = $(holderId); + let holderHeight = $holder.height(); + let windowHeight = $(window).height() - offsetCalculator(); + + // scroll to the bottom of the post and stop any further action if the + // post is yuge, otherwise just jump to the top of the post + // using the lock & holder method + if (holderHeight > windowHeight) { + $(window).scrollTop($holder.offset().top + holderHeight); + _transitioning = false; + return; + } } if (postNumber === 1 && !opts.anchor) { diff --git a/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 b/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 index dbfeb2a389..72157d7910 100644 --- a/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 @@ -263,7 +263,7 @@ createWidget("timeline-scrollarea", { const position = this.position(); this.state.scrolledPost = position.current; - if (position.current === position.scrollPosition || this.site.mobileView) { + if (position.current === position.scrollPosition) { this.sendWidgetAction("jumpToIndex", position.current); } else { this.sendWidgetAction("jumpEnd");