Sort tabs synchronously

This commit is contained in:
YUKI "Piro" Hiroshi 2019-04-19 00:16:53 +09:00 committed by GitHub
parent 2d07657019
commit ab7ccb6fb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -241,12 +241,12 @@ const backgroundLogic = {
const windows = await browser.windows.getAll({populate: true}); const windows = await browser.windows.getAll({populate: true});
for (let windowObj of windows) { // eslint-disable-line prefer-const for (let windowObj of windows) { // eslint-disable-line prefer-const
// First the pinned tabs, then the normal ones. // First the pinned tabs, then the normal ones.
await this._sortTabsInternal(windowObj, true); this._sortTabsInternal(windowObj, true);
await this._sortTabsInternal(windowObj, false); this._sortTabsInternal(windowObj, false);
} }
}, },
async _sortTabsInternal(windowObj, pinnedTabs) { _sortTabsInternal(windowObj, pinnedTabs) {
const tabs = windowObj.tabs; const tabs = windowObj.tabs;
const sortedTabs = []; const sortedTabs = [];
let offset = 0; let offset = 0;
@ -289,11 +289,6 @@ const backgroundLogic = {
if (newIndex < 0) if (newIndex < 0)
newIndex = beforeIds.length; newIndex = beforeIds.length;
let oldIndices = movingIds.map(id => sortedIds.indexOf(id)); let oldIndices = movingIds.map(id => sortedIds.indexOf(id));
// Reject already removed tabs.
movingIds = movingIds.filter((id, index) => oldIndices[index] > -1);
if (movingIds.length === 0)
continue;
oldIndices = oldIndices.filter(index => index > -1);
if (oldIndices[0] < newIndex) if (oldIndices[0] < newIndex)
newIndex--; newIndex--;
browser.tabs.move(movingIds, { browser.tabs.move(movingIds, {