From 2aa1e02beac7af5e5faadcd67fdb7b88e8b7e405 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Wed, 19 Feb 2014 10:56:44 +0100 Subject: [PATCH] New keybinding: Alt-< to switch to previous buffer. Same key as WeeChat --- js/glowingbear.js | 10 ++++++++++ js/models.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 4cb399c..bef5ce3 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -968,6 +968,16 @@ weechat.directive('inputBar', function() { return true; } + // Alt+< -> switch to previous buffer + if ($event.altKey && code === 60) { + var previousBuffer = models.getPreviousBuffer(); + if (previousBuffer) { + models.setActiveBuffer(previousBuffer.id); + $event.preventDefault(); + return true; + } + } + // Escape -> disconnect if (code === 27) { $event.preventDefault(); diff --git a/js/models.js b/js/models.js index 8c3cb38..7cb4a4b 100644 --- a/js/models.js +++ b/js/models.js @@ -329,6 +329,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) var BufferList = []; activeBuffer = null; + previousBuffer = null; unreads = 0; notifications = 0; @@ -368,6 +369,15 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) return activeBuffer; }; + /* + * Returns the previous current active buffer + * + * @return previous buffer object + */ + this.getPreviousBuffer = function() { + return previousBuffer; + }; + /* * Sets the buffer specifiee by bufferId as active. * Deactivates the previous current buffer. @@ -380,7 +390,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) key = 'id'; } - var previousBuffer = this.getActiveBuffer(); + previousBuffer = this.getActiveBuffer(); activeBuffer = _.find(this.model.buffers, function(buffer) { if (buffer[key] === bufferId) {