Jump to any buffer (up to 99) with Alt+J followed by 2 digits.

This commit is contained in:
Tobias Theuer 2017-03-14 23:00:01 +01:00 committed by Lorenz Hübschle-Schneider
parent 7663fa079d
commit 811e76d443
4 changed files with 89 additions and 10 deletions

View file

@ -466,6 +466,33 @@ div.colourbox {
align: right;
}
#sidebar .showjumpkeys .buffer .buffer-jump-key {
transition: all ease-in-out 0.5s;
-webkit-transition: all ease-in-out 0.5s;
transition-delay: 0.2s;
-webkit-transition-delay: 0.2s;
opacity: 0.7;
margin-left: -1.2em;
margin-right: 0.1em;
}
#sidebar .buffer .buffer-jump-key {
margin-left: -1.2em;
margin-right: -0.2em;
font-size: smaller;
transition: all ease-in-out 0.5s;
-webkit-transition: all ease-in-out 0.5s;
opacity: 0;
text-shadow: -1px 0px 4px rgba(255, 255, 255, 0.4),
0px -1px 4px rgba(255, 255, 255, 0.4),
1px 0px 4px rgba(255, 255, 255, 0.4),
0px 1px 4px rgba(255, 255, 255, 0.4);
vertical-align: baseline;
display: inline-block;
width: 1em;
align: right;
}
.gb-modal {
z-index: 1000;
height: 100%;

View file

@ -262,7 +262,7 @@ npm run build-electron-{windows, darwin, linux}</pre>
</div>
</div>
<div id="sidebar" data-state="visible" ng-swipe-left="hideSidebar()" ng-swipe-disable-mouse class="vertical-line">
<ul class="nav nav-pills nav-stacked" ng-class="{'indented': (predicate === 'serverSortKey'), 'showquickkeys': showQuickKeys}">
<ul class="nav nav-pills nav-stacked" ng-class="{'indented': (predicate === 'serverSortKey'), 'showquickkeys': showQuickKeys, 'showjumpkeys': showJumpKeys}">
<li class="bufferfilter">
<form role="form">
<input class="form-control favorite-font" type="text" id="bufferFilter" ng-model="search" ng-keydown="handleSearchBoxKey($event)" placeholder="Search" autocomplete="off">
@ -282,6 +282,7 @@ npm run build-electron-{windows, darwin, linux}</pre>
<a ng-click="setActiveBuffer(buffer.id)" title="{{ buffer.fullName }}" href="#">
<span class="badge pull-right" ng-class="{'danger': buffer.notification}" ng-bind="buffer.notification || buffer.unread"></span>
<span class="buffer-quick-key">{{ buffer.$quickKey }}</span>
<span class="buffer-jump-key">{{ buffer.$jumpKey }}</span>
<span class="buffername">{{ buffer.trimmedName || buffer.fullName }}</span>
</a>
</li>

View file

@ -141,6 +141,7 @@ weechat.filter('getBufferQuickKeys', function () {
if (($scope.search !== undefined && $scope.search.length) || $scope.onlyUnread) {
obj.forEach(function(buf, idx) {
buf.$quickKey = idx < 10 ? (idx + 1) % 10 : '';
buf.$jumpKey = idx + 1;
});
} else {
_.map(obj, function(buffer, idx) {
@ -151,6 +152,7 @@ weechat.filter('getBufferQuickKeys', function () {
return left[0] - right[0] || left[1] - right[1];
}).forEach(function(info, keyIdx) {
obj[ info[2] ].$quickKey = keyIdx < 10 ? (keyIdx + 1) % 10 : '';
obj[ info[2] ].$jumpKey = keyIdx + 1;
});
}
return obj;

View file

@ -246,17 +246,20 @@ weechat.directive('inputBar', function() {
var tmpIterCandidate = $scope.iterCandidate;
$scope.iterCandidate = null;
// Left Alt+[0-9] -> jump to buffer
if ($event.altKey && !$event.ctrlKey && (code > 47 && code < 58)) {
if (code === 48) {
code = 58;
}
var bufferNumber = code - 48 - 1 ;
var bufferNumber;
var sortedBuffers;
var filteredBufferNum;
var activeBufferId;
var activeBufferId;
// if Alt+J was pressed last, we expect two numbers now
if ($rootScope.showJumpKeys && !$event.altKey && (code > 47 && code < 58) && $scope.jumpDecimal === undefined) {
$scope.jumpDecimal = code - 48;
$event.preventDefault();
} else if ($rootScope.showJumpKeys && !$event.altKey && (code > 47 && code < 58) && $scope.jumpDecimal !== undefined) {
bufferNumber = ($scope.jumpDecimal * 10) + (code - 48) - 1;
// quick select filtered entries
if (($scope.$parent.search.length || $scope.$parent.onlyUnread) && $scope.$parent.filteredBuffers.length) {
var filteredBufferNum = $scope.$parent.filteredBuffers[bufferNumber];
filteredBufferNum = $scope.$parent.filteredBuffers[bufferNumber];
if (filteredBufferNum !== undefined) {
activeBufferId = [filteredBufferNum.number, filteredBufferNum.id];
}
@ -264,7 +267,44 @@ weechat.directive('inputBar', function() {
// Map the buffers to only their numbers and IDs so we don't have to
// copy the entire (possibly very large) buffer object, and then sort
// the buffers according to their WeeChat number
var sortedBuffers = _.map(models.getBuffers(), function(buffer) {
sortedBuffers = _.map(models.getBuffers(), function(buffer) {
return [buffer.number, buffer.id];
}).sort(function(left, right) {
// By default, Array.prototype.sort() sorts alphabetically.
// Pass an ordering function to sort by first element.
return left[0] - right[0];
});
activeBufferId = sortedBuffers[bufferNumber];
}
if (activeBufferId) {
$scope.$parent.setActiveBuffer(activeBufferId[1]);
}
$event.preventDefault();
$rootScope.showJumpKeys = false;
$scope.jumpDecimal = undefined;
} else {
$rootScope.showJumpKeys = false;
$scope.jumpDecimal = undefined;
}
// Left Alt+[0-9] -> jump to buffer
if ($event.altKey && !$event.ctrlKey && (code > 47 && code < 58)) {
if (code === 48) {
code = 58;
}
bufferNumber = code - 48 - 1 ;
// quick select filtered entries
if (($scope.$parent.search.length || $scope.$parent.onlyUnread) && $scope.$parent.filteredBuffers.length) {
filteredBufferNum = $scope.$parent.filteredBuffers[bufferNumber];
if (filteredBufferNum !== undefined) {
activeBufferId = [filteredBufferNum.number, filteredBufferNum.id];
}
} else {
// Map the buffers to only their numbers and IDs so we don't have to
// copy the entire (possibly very large) buffer object, and then sort
// the buffers according to their WeeChat number
sortedBuffers = _.map(models.getBuffers(), function(buffer) {
return [buffer.number, buffer.id];
}).sort(function(left, right) {
// By default, Array.prototype.sort() sorts alphabetically.
@ -371,6 +411,15 @@ weechat.directive('inputBar', function() {
connection.sendHotlistClearAll();
}
// Alt+J -> Jump to buffer
if ($event.altKey && (code === 106 || code === 74)) {
$event.preventDefault();
$rootScope.showJumpKeys = true;
return true;
}
var caretPos;
// Arrow up -> go up in history