Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Alt+[0-9] behaviour to respect order of merged buffers #867

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions js/inputbar.js
Expand Up @@ -254,23 +254,24 @@ weechat.directive('inputBar', function() {
if (($scope.$parent.search.length || $scope.$parent.onlyUnread) && $scope.$parent.filteredBuffers.length) {
var filteredBufferNum = $scope.$parent.filteredBuffers[bufferNumber];
if (filteredBufferNum !== undefined) {
activeBufferId = [filteredBufferNum.number, filteredBufferNum.id];
activeBufferId = [filteredBufferNum.number, /*dummy*/ 0, filteredBufferNum.id];
}
} else {
// Map the buffers to only their numbers and IDs so we don't have to
// Map the buffers to only their numbers, indices, 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) {
return [buffer.number, buffer.id];
var buffers = models.getBuffers();
var sortedBuffers = Object.keys(buffers).map(function(key, idx) {
return [buffers[key].number, idx, buffers[key].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];
// Pass an ordering function to sort by key, then index (for merged buffers)
return left[0] - right[0] || left[1] - right[1];
});
activeBufferId = sortedBuffers[bufferNumber];
}
if (activeBufferId) {
$scope.$parent.setActiveBuffer(activeBufferId[1]);
$scope.$parent.setActiveBuffer(activeBufferId[2]);
$event.preventDefault();
}
}
Expand Down Expand Up @@ -359,8 +360,7 @@ weechat.directive('inputBar', function() {

// Alt-h -> Toggle all as read
if ($event.altKey && !$event.ctrlKey && code === 72) {
var buffers = models.getBuffers();
_.each(buffers, function(buffer) {
_.each(models.getBuffers(), function(buffer) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of ridiculous to fix jshint by getting rid of this binding but honestly I find this solution preferable to renaming buffers above. Or maybe pull it up to the beginning of the function?

buffer.unread = 0;
buffer.notification = 0;
});
Expand Down