From db869c6ce46ce40657685ea0bfb19254e79f02aa Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 7 Sep 2017 14:23:51 -0700 Subject: [PATCH] Scroll to bottom when adding a new message (#1450) Added a comment to try to make this easier to understand as you read it. FREEBIE --- js/views/message_list_view.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/views/message_list_view.js b/js/views/message_list_view.js index 2cbf46312..f39506fe3 100644 --- a/js/views/message_list_view.js +++ b/js/views/message_list_view.js @@ -48,7 +48,12 @@ this.$el.scrollTop(this.scrollPosition - this.$el.outerHeight()); }, scrollToBottomIfNeeded: function() { - if (!this.atBottom()) { + // This is counter-intuitive. Our current bottomOffset is reflective of what + // we last measured, not necessarily the current state. And this is called + // after we just made a change to the DOM: inserting a message, or an image + // finished loading. So if we were near the bottom before, we _need_ to be + // at the bottom again. So we scroll to the bottom. + if (this.atBottom()) { this.scrollToBottom(); } },