diff --git a/js/handlers.js b/js/handlers.js index d5dded7..deb88d3 100644 --- a/js/handlers.js +++ b/js/handlers.js @@ -107,10 +107,6 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific var bufferMessage = message.objects[0].content[0]; 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. - models.setActiveBuffer(buffer.id); - */ }; var handleBufferTitleChanged = function(message) { @@ -138,6 +134,15 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific // prefix + fullname, which would happen otherwise). Else, use null so that full_name is used old.trimmedName = obj.short_name.replace(/^[#&+]/, '') || (obj.short_name ? ' ' : null); old.prefix = ['#', '&', '+'].indexOf(obj.short_name.charAt(0)) >= 0 ? obj.short_name.charAt(0) : ''; + + // After a buffer openes we get the name change event from relay protocol + // Here we check our outgoing commands that openes a buffer and switch + // to it if we find the buffer name it the list + var position = models.outgoingQueries.indexOf(old.shortName); + if (position >= 0) { + models.outgoingQueries.splice(position, 1); + models.setActiveBuffer(old.id); + } }; var handleBufferLocalvarChanged = function(message) { diff --git a/js/inputbar.js b/js/inputbar.js index 4540bff..8553c07 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -100,6 +100,19 @@ weechat.directive('inputBar', function() { ab.clear(); } + // Check against a list of commands that opens a new + // buffer and save the name of the buffer so we can + // also automatically switch to the new buffer in gb + var opencommands = ['/query', '/join', '/j', '/q']; + var spacepos = $scope.command.indexOf(' '); + var firstword = $scope.command.substr(0, spacepos); + var index = opencommands.indexOf(firstword); + if (index >= 0) { + var queryName = $scope.command.substring(spacepos + 1); + // Cache our queries so when a buffer gets opened we can open in UI + models.outgoingQueries.push(queryName); + } + // Empty the input after it's sent $scope.command = ''; } diff --git a/js/models.js b/js/models.js index 6860918..efc93d0 100644 --- a/js/models.js +++ b/js/models.js @@ -11,6 +11,9 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) // WeeChat version this.version = null; + // Save outgoing queries + this.outgoingQueries = []; + var parseRichText = function(text) { var textElements = weeChat.Protocol.rawText2Rich(text), typeToClassPrefixFg = {