jumpkeys: filter on entry of first digit
not quite sure whether I like changing the sort order
This commit is contained in:
parent
d9346f5f3e
commit
22cb962e63
4 changed files with 54 additions and 13 deletions
|
@ -281,7 +281,7 @@ npm run build-electron-{windows, darwin, linux}</pre>
|
||||||
'channel_plus': buffer.prefix === '+',
|
'channel_plus': buffer.prefix === '+',
|
||||||
'channel_ampersand': buffer.prefix === '&',
|
'channel_ampersand': buffer.prefix === '&',
|
||||||
'private': buffer.type === 'private'}"
|
'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="#">
|
<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="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-quick-key">{{ buffer.$quickKey }}</span>
|
||||||
|
|
|
@ -141,7 +141,6 @@ weechat.filter('getBufferQuickKeys', function () {
|
||||||
if (($scope.search !== undefined && $scope.search.length) || $scope.onlyUnread) {
|
if (($scope.search !== undefined && $scope.search.length) || $scope.onlyUnread) {
|
||||||
obj.forEach(function(buf, idx) {
|
obj.forEach(function(buf, idx) {
|
||||||
buf.$quickKey = idx < 10 ? (idx + 1) % 10 : '';
|
buf.$quickKey = idx < 10 ? (idx + 1) % 10 : '';
|
||||||
buf.$jumpKey = idx + 1;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_.map(obj, function(buffer, idx) {
|
_.map(obj, function(buffer, idx) {
|
||||||
|
@ -152,7 +151,11 @@ weechat.filter('getBufferQuickKeys', function () {
|
||||||
return left[0] - right[0] || left[1] - right[1];
|
return left[0] - right[0] || left[1] - right[1];
|
||||||
}).forEach(function(info, keyIdx) {
|
}).forEach(function(info, keyIdx) {
|
||||||
obj[ info[2] ].$quickKey = keyIdx < 10 ? (keyIdx + 1) % 10 : '';
|
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;
|
return obj;
|
||||||
|
|
|
@ -359,9 +359,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Watch model and update channel sorting when it changes
|
// Watch model and update channel sorting when it changes
|
||||||
settings.addCallback('orderbyserver', function(orderbyserver) {
|
var set_filter_predicate = function(orderbyserver) {
|
||||||
$rootScope.predicate = orderbyserver ? 'serverSortKey' : 'number';
|
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) {
|
settings.addCallback('useFavico', function(useFavico) {
|
||||||
// this check is necessary as this is called on page load, too
|
// 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;
|
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
|
// Watch model and update show setting when it changes
|
||||||
settings.addCallback('nonicklist', function() {
|
settings.addCallback('nonicklist', function() {
|
||||||
$scope.showNicklist = $scope.updateShowNicklist();
|
$scope.showNicklist = $scope.updateShowNicklist();
|
||||||
|
|
|
@ -253,24 +253,32 @@ weechat.directive('inputBar', function() {
|
||||||
|
|
||||||
// if Alt+J was pressed last...
|
// if Alt+J was pressed last...
|
||||||
if ($rootScope.showJumpKeys) {
|
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
|
// ... we expect two digits now
|
||||||
if (!$event.altKey && (code > 47 && code < 58)) {
|
if (!$event.altKey && (code > 47 && code < 58)) {
|
||||||
// first digit
|
// first digit
|
||||||
if ($scope.jumpDecimal === undefined) {
|
if ($rootScope.jumpDecimal === undefined) {
|
||||||
$scope.jumpDecimal = code - 48;
|
$rootScope.jumpDecimal = code - 48;
|
||||||
$event.preventDefault();
|
$event.preventDefault();
|
||||||
// second digit
|
$scope.$parent.search = $rootScope.jumpDecimal;
|
||||||
|
$rootScope.refresh_filter_predicate();
|
||||||
|
// second digit, jump to correct buffer
|
||||||
} else {
|
} else {
|
||||||
bufferNumber = ($rootScope.jumpDecimal * 10) + (code - 48);
|
bufferNumber = ($rootScope.jumpDecimal * 10) + (code - 48);
|
||||||
$scope.$parent.setActiveBuffer(bufferNumber, '$jumpKey');
|
$scope.$parent.setActiveBuffer(bufferNumber, '$jumpKey');
|
||||||
|
|
||||||
$event.preventDefault();
|
$event.preventDefault();
|
||||||
$rootScope.showJumpKeys = false;
|
cleanup();
|
||||||
$scope.jumpDecimal = undefined;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$rootScope.showJumpKeys = false;
|
// Not a decimal digit, abort
|
||||||
$scope.jumpDecimal = undefined;
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue