From 84270655eeb560e776c02f42b70fbd6530bb18b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= <lorenz-dev@lgh-alumni.de> Date: Sun, 4 May 2014 11:21:35 +0100 Subject: [PATCH] Don't send input bar contents on buffer switch Fixes #277 --- js/glowingbear.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 45b2858..e4b1086 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -703,7 +703,12 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.search = ''; if (!$rootScope.isMobileUi()) { - document.getElementById('sendMessage').focus(); + // This needs to happen asynchronously to prevent the enter key handler + // of the input bar to be triggered on buffer switch via the search. + // Otherwise its current contents would be sent to the new buffer + setTimeout(function() { + document.getElementById('sendMessage').focus(); + }, 0); } }); @@ -1371,7 +1376,7 @@ weechat.directive('inputBar', function() { // Enter to submit, shift-enter for newline // - if (code == 13 && !$event.shiftKey) { + if (code == 13 && !$event.shiftKey && document.activeElement === inputNode) { $event.preventDefault(); $scope.sendMessage(); return true;