From c501215bae5f00cc6f619a8d7a6de49763903585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Thu, 4 Sep 2014 22:34:52 +0100 Subject: [PATCH] Re-enable "fetch more lines" after trimming lines on buffer switch Fixes #404 --- js/glowingbear.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 78da583..60ef1af 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -108,10 +108,14 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // case where a buffer is opened for the first time ;) var minRetainUnread = ab.lines.length - unreadSum + 5; // do not discard unread lines and keep 5 additional lines for context var surplusLines = ab.lines.length - (2 * $scope.lines_per_screen + 10); // retain up to 2*(screenful + 10) + 10 lines because magic numbers - var linesToRemove = Math.max(0, Math.min(minRetainUnread, surplusLines)); - ab.lines.splice(0, linesToRemove); // remove the lines from the buffer - ab.requestedLines -= linesToRemove; // to ensure that the correct amount of lines is fetched should more be requested - ab.lastSeen -= linesToRemove; // adjust readmarker + var linesToRemove = Math.min(minRetainUnread, surplusLines); + + if (linesToRemove > 0) { + ab.lines.splice(0, linesToRemove); // remove the lines from the buffer + ab.requestedLines -= linesToRemove; // to ensure that the correct amount of lines is fetched should more be requested + ab.lastSeen -= linesToRemove; // adjust readmarker + ab.allLinesFetched = false; // we just removed lines, so we don't have all of them. re-enable "fetch more lines" + } $scope.bufferlines = ab.lines; $scope.nicklist = ab.nicklist;