From 5a90e2e830d26bf76e5fea8cd9ca52b69759e545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 10 Feb 2014 18:43:59 +0000 Subject: [PATCH] Fix scrolling issue and reduce the number of scrolling events on startup Don't trigger scrolling on each line when batch loading lines --- js/glowingbear.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 62c9a0d..1a614db 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -22,7 +22,7 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc models.closeBuffer(buffer); }; - var handleLine = function(line, initial) { + var handleLine = function(line, initial, loadingMoreLines) { var message = new models.BufferLine(line); var buffer = models.getBuffer(message.buffer); buffer.requestedLines++; @@ -35,7 +35,7 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc buffer.lastSeen++; } - if (buffer.active) { + if (buffer.active && !initial && !loadingMoreLines) { $rootScope.scrollWithBuffer(); } @@ -89,11 +89,11 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc * * (lineinfo) messages are specified by this client. It is request after bufinfo completes */ - var handleLineInfo = function(message, initial) { + var handleLineInfo = function(message, initial, loadingMoreLines) { var lines = message.objects[0].content.reverse(); if (initial === undefined) initial = true; lines.forEach(function(l) { - handleLine(l, initial); + handleLine(l, initial, loadingMoreLines); }); }; @@ -293,6 +293,7 @@ function($rootScope, }) ).then(function(lineinfo) { handlers.handleLineInfo(lineinfo); + $rootScope.scrollWithBuffer(true); }); ngWebsockets.send( @@ -400,9 +401,10 @@ function($rootScope, var oldLength = buffer.lines.length; buffer.lines.length = 0; buffer.requestedLines = 0; - handlers.handleLineInfo(lineinfo, false); + handlers.handleLineInfo(lineinfo, false, true); buffer.lastSeen = buffer.lines.length - oldLength - 1; $rootScope.loadingLines = false; + $rootScope.scrollWithBuffer(true); }); } @@ -608,7 +610,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', var readmarker = document.getElementById('readmarker'); if (nonIncremental && readmarker) { // Switching channels, scroll to read marker - readmarker.scrollIntoView(); + readmarker.scrollIntoViewIfNeeded(); } else { // New message, scroll with buffer (i.e. to bottom) bl.scrollTop = bl.scrollHeight - bl.clientHeight;