jumpkeys: filter on entry of first digit

not quite sure whether I like changing the sort order
This commit is contained in:
Lorenz Hübschle-Schneider 2017-03-18 16:31:55 +01:00
parent d9346f5f3e
commit 22cb962e63
4 changed files with 54 additions and 13 deletions

View file

@ -281,7 +281,7 @@ npm run build-electron-{windows, darwin, linux}</pre>
'channel_plus': buffer.prefix === '+',
'channel_ampersand': buffer.prefix === '&',
'private': buffer.type === 'private'}"
ng-repeat="(key, buffer) in (filteredBuffers = (getBuffers() | toArray:'withidx' | filter:{fullName:search} | filter:hasUnread | orderBy:predicate | getBufferQuickKeys:this))">
ng-repeat="(key, buffer) in (filteredBuffers = (getBuffers() | toArray:'withidx' | filter:bufferlistfilter | filter:hasUnread | orderBy:predicate | getBufferQuickKeys:this))">
<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>

View file

@ -141,7 +141,6 @@ 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) {
@ -152,7 +151,11 @@ 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;
// Don't update jump key upon filtering
if (obj[ info[2] ].$jumpKey === undefined) {
// Only assign jump keys up to 99
obj[ info[2] ].$jumpKey = (keyIdx < 99) ? keyIdx + 1 : '';
}
});
}
return obj;

View file

@ -359,9 +359,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
};
// Watch model and update channel sorting when it changes
settings.addCallback('orderbyserver', function(orderbyserver) {
$rootScope.predicate = orderbyserver ? 'serverSortKey' : 'number';
});
var set_filter_predicate = function(orderbyserver) {
if ($rootScope.showJumpKeys) {
$rootScope.predicate = '$jumpKey';
} else if (orderbyserver) {
$rootScope.predicate = 'serverSortKey';
} else {
$rootScope.predicate = 'number';
}
};
settings.addCallback('orderbyserver', set_filter_predicate);
// convenience wrapper for jump keys
$rootScope.refresh_filter_predicate = function() {
set_filter_predicate(settings.orderbyserver);
};
settings.addCallback('useFavico', function(useFavico) {
// this check is necessary as this is called on page load, too
@ -658,6 +669,25 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
return !buffer.hidden;
};
// filter bufferlist for search or jump key
$rootScope.bufferlistfilter = function(buffer) {
if ($rootScope.showJumpKeys) {
// filter by jump key
if ($rootScope.jumpDecimal === undefined) {
// no digit input yet, show all buffers
return true;
} else {
var min_jumpKey = 10 * $rootScope.jumpDecimal,
max_jumpKey = 10 * ($rootScope.jumpDecimal + 1);
return (min_jumpKey <= buffer.$jumpKey) &&
(buffer.$jumpKey < max_jumpKey);
}
} else {
// filter by buffer name
return buffer.fullName.indexOf($scope.search) !== -1;
}
};
// Watch model and update show setting when it changes
settings.addCallback('nonicklist', function() {
$scope.showNicklist = $scope.updateShowNicklist();

View file

@ -253,24 +253,32 @@ weechat.directive('inputBar', function() {
// if Alt+J was pressed last...
if ($rootScope.showJumpKeys) {
var cleanup = function() { // cleanup helper
$rootScope.showJumpKeys = false;
$rootScope.jumpDecimal = undefined;
$scope.$parent.search = '';
$rootScope.refresh_filter_predicate();
};
// ... we expect two digits now
if (!$event.altKey && (code > 47 && code < 58)) {
// first digit
if ($scope.jumpDecimal === undefined) {
$scope.jumpDecimal = code - 48;
if ($rootScope.jumpDecimal === undefined) {
$rootScope.jumpDecimal = code - 48;
$event.preventDefault();
// second digit
$scope.$parent.search = $rootScope.jumpDecimal;
$rootScope.refresh_filter_predicate();
// second digit, jump to correct buffer
} else {
bufferNumber = ($rootScope.jumpDecimal * 10) + (code - 48);
$scope.$parent.setActiveBuffer(bufferNumber, '$jumpKey');
$event.preventDefault();
$rootScope.showJumpKeys = false;
$scope.jumpDecimal = undefined;
cleanup();
}
} else {
$rootScope.showJumpKeys = false;
$scope.jumpDecimal = undefined;
// Not a decimal digit, abort
cleanup();
}
}