Commit 131f81df authored by Pavel Feldman's avatar Pavel Feldman Committed by Commit Bot

DevTools: persist tab order relatively to the untouched panels as well.

Bug: 930212
Change-Id: I99100d4fd6fd952f29763de8b33ce277a85ffb58
Reviewed-on: https://chromium-review.googlesource.com/c/1471258Reviewed-by: default avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631971}
parent 137fc847
...@@ -632,8 +632,7 @@ UI.ViewManager._TabbedLocation = class extends UI.ViewManager._Location { ...@@ -632,8 +632,7 @@ UI.ViewManager._TabbedLocation = class extends UI.ViewManager._Location {
this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabClosed, this._tabClosed, this); this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabClosed, this._tabClosed, this);
this._closeableTabSetting = Common.settings.createSetting(location + '-closeableTabs', {}); this._closeableTabSetting = Common.settings.createSetting(location + '-closeableTabs', {});
this._tabOrderSetting = Common.settings.createSetting(location + '-tabOrder', {}); this._tabOrderSetting = Common.settings.createSetting(location + '-tabOrder', {});
this._tabbedPane.addEventListener( this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabOrderChanged, this._persistTabOrder, this);
UI.TabbedPane.Events.TabOrderChanged, event => this._persistTabOrder(event.data['tabId']));
if (restoreSelection) if (restoreSelection)
this._lastSelectedTabSetting = Common.settings.createSetting(location + '-selectedTab', ''); this._lastSelectedTabSetting = Common.settings.createSetting(location + '-selectedTab', '');
this._defaultTab = defaultTab; this._defaultTab = defaultTab;
...@@ -766,7 +765,7 @@ UI.ViewManager._TabbedLocation = class extends UI.ViewManager._Location { ...@@ -766,7 +765,7 @@ UI.ViewManager._TabbedLocation = class extends UI.ViewManager._Location {
this._closeableTabSetting.set(tabs); this._closeableTabSetting.set(tabs);
} }
} }
this._persistTabOrder(view.viewId()); this._persistTabOrder();
} }
/** /**
...@@ -822,20 +821,23 @@ UI.ViewManager._TabbedLocation = class extends UI.ViewManager._Location { ...@@ -822,20 +821,23 @@ UI.ViewManager._TabbedLocation = class extends UI.ViewManager._Location {
this._views.get(id).disposeView(); this._views.get(id).disposeView();
} }
/** _persistTabOrder() {
* @param {string} tabId
*/
_persistTabOrder(tabId) {
const tabIds = this._tabbedPane.tabIds(); const tabIds = this._tabbedPane.tabIds();
const previousId = tabIds[tabIds.indexOf(tabId) - 1];
const orders = this._tabOrderSetting.get();
orders[tabId] = previousId && orders[previousId] ? orders[previousId] + 1 : 0;
const keys = Object.keys(orders);
keys.sort((a, b) => orders[a] - orders[b]);
const tabOrders = {}; const tabOrders = {};
for (let i = 0; i < keys.length; i++) for (let i = 0; i < tabIds.length; i++)
tabOrders[keys[i]] = (i + 1) * UI.ViewManager._TabbedLocation.orderStep; tabOrders[tabIds[i]] = (i + 1) * UI.ViewManager._TabbedLocation.orderStep;
const oldTabOrder = this._tabOrderSetting.get();
const oldTabArray = Object.keys(oldTabOrder);
oldTabArray.sort((a, b) => oldTabOrder[a] - oldTabOrder[b]);
let lastOrder = 0;
for (const key of oldTabArray) {
if (key in tabOrders) {
lastOrder = tabOrders[key];
continue;
}
tabOrders[key] = ++lastOrder;
}
this._tabOrderSetting.set(tabOrders); this._tabOrderSetting.set(tabOrders);
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment