From 6271dc65779529a97927cd7ce4b64fea100c57ba Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sat, 12 Oct 2013 12:54:13 -0400 Subject: [PATCH] shortcuts: implement switching buffer using ALT-number --- js/models.js | 11 +++++++++++ js/websockets.js | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/js/models.js b/js/models.js index 8f3b2a1..248e760 100644 --- a/js/models.js +++ b/js/models.js @@ -115,6 +115,17 @@ models.service('models', ['colors', function(colors) { this.model.buffers[buffer.id] = buffer; } + this.getBufferByIndex = function(index) { + var i = 0; + + for (var v in BufferList) { + if (index == ++i) { + return BufferList[v]; + } + } + + } + /* * Returns the current active buffer * diff --git a/js/websockets.js b/js/websockets.js index f6901de..75ea0ac 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -536,6 +536,19 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Support different browser quirks var code = $event.keyCode ? $event.keyCode : $event.charCode; + if ($event.altKey && (code > 47 && code < 58)) { + if (code == 48) { + code = 58; + } + + var bufferNumber = code - 48; + var activeBuffer = models.getBufferByIndex(bufferNumber); + if (activeBuffer) { + models.setActiveBuffer(activeBuffer.id); + $event.preventDefault(); + } + } + //console.log('keypress', $event.charCode, $event.altKey); // Handle alt-a