From 0b8a3eb045ae31e6f8d865814a71402ba470deec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 1 Jul 2014 19:41:27 +0100 Subject: [PATCH] Don't trim unread lines Also fix read marker after trimming --- js/glowingbear.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 4869862..65104f8 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -87,7 +87,7 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', function var buffer = new models.Buffer(bufferMessage); models.addBuffer(buffer); /* Until we can decide if user asked for this buffer to be opened - * or not we will let user click opened buffers. + * or not we will let user click opened buffers. models.setActiveBuffer(buffer.id); */ }; @@ -699,9 +699,14 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $rootScope.$on('activeBufferChanged', function(event, unreadSum) { var ab = models.getActiveBuffer(); - // trim lines to 2 screenfuls + 10 lines - ab.lines.splice(0, ab.lines.length - (2 * $scope.lines_per_screen + 10)); - ab.requestedLines = ab.lines.length; + // Discard surplus lines. This is done *before* lines are fetched because that saves us the effort of special handling for the + // 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 = ab.lines.length; // to ensure that the correct amount of lines is fetched should more be requested + ab.lastSeen -= linesToRemove; // adjust readmarker $scope.bufferlines = ab.lines; $scope.nicklist = ab.nicklist; @@ -1239,7 +1244,7 @@ weechat.directive('inputBar', function() { return { templateUrl: 'directives/input.html', - + scope: { inputId: '@inputId' },