Fix scrolling behaviour for good (?)

This commit is contained in:
Lorenz H-S 2013-12-28 16:50:31 +01:00
parent fe0c070a6c
commit f38c4b020e

View file

@ -480,7 +480,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} }
$rootScope.$on('activeBufferChanged', function() { $rootScope.$on('activeBufferChanged', function() {
$rootScope.scrollWithBuffer(); $rootScope.scrollWithBuffer(true);
var ab = models.getActiveBuffer(); var ab = models.getActiveBuffer();
$rootScope.pageTitle = ab.shortName + ' | ' + ab.title; $rootScope.pageTitle = ab.shortName + ' | ' + ab.title;
@ -577,14 +577,24 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} }
}; };
$rootScope.scrollWithBuffer = function() { $rootScope.scrollWithBuffer = function(nonIncremental) {
// FIXME doesn't work if the settimeout runs without a short delay // 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 scroll = function() {
var bl = document.getElementById('bufferlines');
var sTop = bl.scrollTop; var sTop = bl.scrollTop;
var sVal = bl.scrollHeight - bl.clientHeight; // Determine if we want to scroll at all
if(sTop == sVal) { if (nonIncremental && sTop < sVal || sTop == sVal) {
bl.scrollTop = 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 // Here be scrolling dragons