Get the current priorities using the tabIds list instead of the regions

The tabIds list is already sorted by priority and insertion order, while
the regions order is undefined and has to be explicitly sorted.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2017-11-11 14:08:41 +01:00
Родитель 43e3054c50
Коммит c8b5d2798f
1 изменённых файлов: 5 добавлений и 14 удалений

Просмотреть файл

@ -129,20 +129,11 @@
* @return int the insertion index.
*/
_getIndexForTabHeaderPriority: function(priority) {
// this.getRegions() returns an object that acts as a map, but it
// has no "length" property; _.map creates an array, thus ensuring
// that there is a "length" property to know the current number of
// tab headers.
var currentPriorities = _.map(this.getRegions(), function(region) {
return region.currentView.getOption('priority');
});
// By default sort() converts the values to strings and sorts them
// in ascending order using their Unicode value; a custom function
// must be used to sort them by their numerical value instead.
currentPriorities.sort(function(a, b) {
return a - b;
}).reverse();
// _.map creates an array, so "currentPriorities" will contain a
// "length" property.
var currentPriorities = _.map(this._tabIds, _.bind(function(tabId) {
return this.getRegion(tabId).currentView.getOption('priority');
}, this));
var index = _.findIndex(currentPriorities, function(currentPriority) {
return priority > currentPriority;