Mercurial > addons > firefox-addons > tab-mover
changeset 32:aaed574396b8
Move pinned tabs correctly
Pinned tabs need to be handled separately, the must either be moved before or
after other pinned tabs or to index 0. The built-in behavior of the "Move to
New Window" action is to unpin tabs. Follow this behavior for consistency.
Furthermore, active, pinned tabs are not marked as active. Handle this case as
well.
author | Guido Berhoerster <guido+tab-mover@berhoerster.name> |
---|---|
date | Thu, 08 Apr 2021 11:22:24 +0200 |
parents | e22195f84c6d |
children | df8ade6f65c4 |
files | background.js |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/background.js Mon Mar 01 11:11:22 2021 +0100 +++ b/background.js Thu Apr 08 11:22:24 2021 +0200 @@ -33,6 +33,12 @@ windowId: tab.windowId }) : [tab]; let activeTab = selectedTabs.find(tab => tab.active); + + // unpin tabs before moving, this matches the built-in behavior + let unpinningTabs = selectedTabs.flatMap(tab => + tab.pinned ? [browser.tabs.update(tab.id, {pinned: false})] : []); + await Promise.all(unpinningTabs.map(p => p.catch(e => e))); + await browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id), {windowId: targetWindowId, index: -1}); @@ -40,7 +46,7 @@ // tabs since this resets the selected tabs await browser.tabs.update(activeTab.id, {active: true}); for (let tab of selectedTabs) { - if (tab.id !== activeTab.id) { + if (typeof activeTab === 'undefined' || tab.id !== activeTab.id) { browser.tabs.update(tab.id, {active: false, highlighted: true}); } }