From 3f595ea0acc4bbdbcc740ccc5ecc01fdcc9904a3 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Wed, 7 May 2014 18:33:47 +0200 Subject: [PATCH] Don't send empty commands, use angular model instead of accessing element value directly. Fixes problem with pressing enter will send previous value in history. --- js/glowingbear.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 195a1cb..4a742be 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -1264,22 +1264,27 @@ weechat.directive('inputBar', function() { var input = $scope.getInputNode(); var ab = models.getActiveBuffer(); - // log to buffer history - ab.addToHistory(input.value); + // It's undefined early in the lifecycle of the program. + // Don't send empty commands + if($scope.command !== undefined && $scope.command !== '') { - // Split the command into multiple commands based on line breaks - _.each($scope.command.split(/\r?\n/), function(line) { - connection.sendMessage(line); - }); + // log to buffer history + ab.addToHistory($scope.command); - // Check for /clear command - if ($scope.command === '/buffer clear' || $scope.command === '/c') { - $log.debug('Clearing lines'); - ab.clear(); + // 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 === '/buffer clear' || $scope.command === '/c') { + $log.debug('Clearing lines'); + ab.clear(); + } + + // Empty the input after it's sent + $scope.command = ''; } - - // Empty the input after it's sent - input.value = ''; }; // Handle key presses in the input bar