"use strict";

angular.module('arethusa.core').directive('sidepanel', [
  'keyCapture',
  function(keyCapture) {
    return {
      restrict: 'A',
      link: function(scope, element, attrs) {
        var minIndex = 0;

        function currentIndex() {
          return scope.subPlugins.indexOf(scope.activePlugin);
        }

        function maxIndex() {
          return scope.subPlugins.length - 1;
        }

        function selectPluginByIndex(index) {
          var plugin = scope.subPlugins[index];
          scope.declareActive(plugin);
        }

        function moveToNext() {
          var current = currentIndex();
          var index = current === maxIndex() ? minIndex : current + 1;
          selectPluginByIndex(index);
        }

        function moveToPrev() {
          var current = currentIndex();
          var index = current === minIndex ? maxIndex() : current - 1;
          selectPluginByIndex(index);
        }

        var conf = keyCapture.conf().sidepanel || {};
        var nextKey = conf.nextTab || 'j';
        var prevKey = conf.prevTab || 'k';
        var captures = {};
        captures[nextKey] = moveToNext;
        captures[prevKey] = moveToPrev;

        keyCapture.registerCaptures(captures, scope);
      }
    };
  }
]);

@@ -65,16 +65,31 @@
 nel', %5B%0A
+  'sidepanel',%0A
   'keyCa
@@ -107,16 +107,27 @@
 unction(
+sidepanel, 
 keyCaptu
@@ -1102,16 +1102,59 @@
 %7C%7C 'k';%0A
+        var toggle  = conf.toggle  %7C%7C 's';%0A
         
@@ -1251,16 +1251,62 @@
 eToPrev;
+%0A        captures%5Btoggle%5D  = sidepanel.toggle;
 %0A%0A      

Add default keybinding to toggle sidepanel