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 Apr 08 11:22:24 2021 +0200 (5 months ago)
parents e22195f84c6d
children df8ade6f65c4
files background.js
line diff
     1.1 --- a/background.js	Mon Mar 01 11:11:22 2021 +0100
     1.2 +++ b/background.js	Thu Apr 08 11:22:24 2021 +0200
     1.3 @@ -33,6 +33,12 @@
     1.4          windowId: tab.windowId
     1.5      }) : [tab];
     1.6      let activeTab = selectedTabs.find(tab => tab.active);
     1.7 +
     1.8 +    // unpin tabs before moving, this matches the built-in behavior
     1.9 +    let unpinningTabs = selectedTabs.flatMap(tab =>
    1.10 +        tab.pinned ? [browser.tabs.update(tab.id, {pinned: false})] : []);
    1.11 +    await Promise.all(unpinningTabs.map(p => p.catch(e => e)));
    1.12 +
    1.13      await browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id),
    1.14              {windowId: targetWindowId, index: -1});
    1.15  
    1.16 @@ -40,7 +46,7 @@
    1.17      // tabs since this resets the selected tabs
    1.18      await browser.tabs.update(activeTab.id, {active: true});
    1.19      for (let tab of selectedTabs) {
    1.20 -        if (tab.id !== activeTab.id) {
    1.21 +        if (typeof activeTab === 'undefined' || tab.id !== activeTab.id) {
    1.22              browser.tabs.update(tab.id, {active: false, highlighted: true});
    1.23          }
    1.24      }