From 3b60f992b4623f4d8eac2451f9062e81334df6f2 Mon Sep 17 00:00:00 2001 From: Mukunda Modell Date: Tue, 1 Dec 2015 17:02:32 -0600 Subject: [PATCH] Switch to adjacent buffer with alt+arrow Use alt+up and alt+down to switch to previous / next buffer. Works when bufferlist is nested or flat. This implements issue #511. --- js/glowingbear.js | 12 ++++++++++++ js/inputbar.js | 8 ++++++++ js/models.js | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 3e3a2e2..9c2caed 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -727,6 +727,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', settings.nonicklist = !settings.nonicklist; }; + $rootScope.switchToAdjacentBuffer = function(direction) { + // direction is +1 for next buffer, -1 for previous buffer + var sortedBuffers = _.sortBy($scope.getBuffers(), $rootScope.predicate); + var activeBuffer = models.getActiveBuffer(); + var index = sortedBuffers.indexOf(activeBuffer); + if (index >= 0) { + var newBuffer = sortedBuffers[index + direction]; + if (newBuffer) { + $scope.setActiveBuffer(newBuffer.id); + } + } + }; $scope.handleSearchBoxKey = function($event) { // Support different browser quirks diff --git a/js/inputbar.js b/js/inputbar.js index 9d18506..2cd24c7 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -294,6 +294,14 @@ weechat.directive('inputBar', function() { return true; } + // Alt+Arrow up/down -> switch to prev/next adjacent buffer + if ($event.altKey && !$event.ctrlKey && (code === 38 || code === 40)) { + $event.preventDefault(); + var direction = code - 39; + $rootScope.switchToAdjacentBuffer(direction); + return true; + } + // Alt+L -> focus on input bar if ($event.altKey && (code === 76 || code === 108)) { $event.preventDefault(); diff --git a/js/models.js b/js/models.js index 8a4dd43..5b8a7bb 100644 --- a/js/models.js +++ b/js/models.js @@ -84,7 +84,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) var notification = 0; var unread = 0; var lastSeen = -1; - var serverSortKey = fullName.replace(/^irc\.server\.(\w+)/, "irc.$1"); + var serverSortKey = fullName.replace(/^irc\.server\.(\w+)/, "irc.$1").toLowerCase(); // There are two kinds of types: bufferType (free vs formatted) and // the kind of type that distinguishes queries from channels etc var bufferType = message.type;