From f21cf4c0462a5161352d2b35327b74fa5e61d1df Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Tue, 6 May 2014 18:38:20 +0200 Subject: [PATCH 1/2] Support clearing of buffer lines with command /c or /clear --- js/glowingbear.js | 18 ++++++++++++++++-- js/models.js | 10 ++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 5594461..43acdf8 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -427,6 +427,7 @@ function($rootScope, var fetchMoreLines = function(numLines) { + $log.debug('Fetching ', numLines, ' lines'); var buffer = models.getActiveBuffer(); if (numLines === undefined) { // Math.max(undefined, *) = NaN -> need a number here @@ -506,7 +507,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', q.push(scope.$$nextSibling); } } - console.log(watchers); + $log.debug(watchers); }; @@ -1208,6 +1209,7 @@ weechat.directive('inputBar', function() { controller: function($rootScope, $scope, $element, + $log, connection, models) { @@ -1251,11 +1253,23 @@ weechat.directive('inputBar', function() { $scope.sendMessage = function() { var input = $scope.getInputNode(); - models.getActiveBuffer().addToHistory(input.value); // log to buffer history + var ab = models.getActiveBuffer(); + + // log to buffer history + ab.addToHistory(input.value); + // Split the command into multiple commands based on line breaks _.each($scope.command.split(/\r?\n/), function(line) { connection.sendMessage(line); }); + + // Check for /clear command + if ($scope.command === '/clear' || $scope.command === '/c') { + $log.debug('Clearing lines'); + ab.clear(); + } + + // Empty the input after it's sent input.value = ''; }; diff --git a/js/models.js b/js/models.js index 08af87d..d256afb 100644 --- a/js/models.js +++ b/js/models.js @@ -19,6 +19,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) var notify = 3; // Default 3 == message var lines = []; var requestedLines = 0; + var allLinesFetched = false; var nicklist = {}; var history = []; var historyPos = 0; @@ -197,6 +198,14 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) return nicklist.hasOwnProperty('root'); }; + /* Clear all our buffer lines */ + var clear = function() { + while(lines.length > 0) { + lines.pop(); + } + requestedLines = 0; + }; + return { id: pointer, fullName: fullName, @@ -204,6 +213,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) number: number, title: title, lines: lines, + clear: clear, requestedLines: requestedLines, addLine: addLine, lastSeen: lastSeen, From 695c429c4fc53e1eb23ab28d35d3f2cd875fa5e1 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Wed, 7 May 2014 18:55:48 +0200 Subject: [PATCH 2/2] Only support the weechat defaults for clearing buffer --- js/glowingbear.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 43acdf8..432e2a9 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -1264,7 +1264,7 @@ weechat.directive('inputBar', function() { }); // Check for /clear command - if ($scope.command === '/clear' || $scope.command === '/c') { + if ($scope.command === '/buffer clear' || $scope.command === '/c') { $log.debug('Clearing lines'); ab.clear(); }