From f38c4b020e1a48e86542d003a319a5d0f84f5c32 Mon Sep 17 00:00:00 2001 From: Lorenz H-S Date: Sat, 28 Dec 2013 16:50:31 +0100 Subject: [PATCH] Fix scrolling behaviour for good (?) --- js/websockets.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/js/websockets.js b/js/websockets.js index c0476af..17daf3c 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -480,7 +480,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } $rootScope.$on('activeBufferChanged', function() { - $rootScope.scrollWithBuffer(); + $rootScope.scrollWithBuffer(true); var ab = models.getActiveBuffer(); $rootScope.pageTitle = ab.shortName + ' | ' + ab.title; @@ -577,14 +577,24 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } }; - $rootScope.scrollWithBuffer = function() { - // FIXME doesn't work if the settimeout runs without a short delay + $rootScope.scrollWithBuffer = function(nonIncremental) { + // First, get scrolling status *before* modification + // This is required to determine where we were in the buffer pre-change + var bl = document.getElementById('bufferlines'); + var sVal = bl.scrollHeight - bl.clientHeight; + var scroll = function() { - var bl = document.getElementById('bufferlines'); var sTop = bl.scrollTop; - var sVal = bl.scrollHeight - bl.clientHeight; - if(sTop == sVal) { - bl.scrollTop = sVal; + // Determine if we want to scroll at all + if (nonIncremental && sTop < sVal || sTop == sVal) { + var readmarker = document.getElementById('readmarker'); + if(nonIncremental && readmarker) { + // Switching channels, scroll to read marker + readmarker.scrollIntoView(); + } else { + // New message, scroll with buffer (i.e. to bottom) + bl.scrollTop = bl.scrollHeight - bl.clientHeight; + } } }; // Here be scrolling dragons