addons/firefox-addons/tab-mover

changeset 24:f418a6305f17

Allow moving multiple highlighted tabs

Allow moving multiple highlighted tabs using the new multiselect feature
available in Firefox 62.0.
author Guido Berhoerster <guido+tab-mover@berhoerster.name>
date Sun Nov 25 13:53:02 2018 +0100 (2018-11-25)
parents 4704e5216412
children fa504a211b26
files README background.js
line diff
     1.1 --- a/README	Sun Nov 25 13:27:47 2018 +0100
     1.2 +++ b/README	Sun Nov 25 13:53:02 2018 +0100
     1.3 @@ -14,17 +14,16 @@
     1.4  In order to move a tab between windows, open the tab context menu by clicking
     1.5  on the tab using the right mouse button, then open the submenu named
     1.6  "Tab Mover", and finally select a window from the submenu named "Move to
     1.7 -Window".
     1.8 +Window".  Multiple tabs can be moved by opening the context menu on a tab
     1.9 +belonging to a group of highlighted tabs (highlighting multiple tabs is
    1.10 +possible starting from Firefox 62 if the preference browser.tabs.multiselect
    1.11 +is set to "true").
    1.12  
    1.13  In order to close a tab in a window in incognito mode and to reopen its URL
    1.14  in a normal window or vice versa, open the tab context menu by clicking the
    1.15  tab using the right mouse button, then open the submenu named "Tab Mover", and
    1.16  finally select a window from the submenu named "Close and Reopen in Window".
    1.17  
    1.18 -When using Firefox version 52 or earlier the "Tab Mover" submenu is located in
    1.19 -the page context menu instead of the tab context menu. The page context menu
    1.20 -can be opened by clicking anywhere on a page using the right mouse button.
    1.21 -
    1.22  Contact
    1.23  -------
    1.24  
     2.1 --- a/background.js	Sun Nov 25 13:27:47 2018 +0100
     2.2 +++ b/background.js	Sun Nov 25 13:53:02 2018 +0100
     2.3 @@ -25,20 +25,36 @@
     2.4      });
     2.5  }
     2.6  
     2.7 -async function moveTab(tab, targetWindowId) {
     2.8 -    browser.tabs.move(tab.id, {windowId: targetWindowId, index: -1});
     2.9 +async function moveTabs(tab, targetWindowId) {
    2.10 +    // if the current tab is part of a highlighted group then move the whole
    2.11 +    // group
    2.12 +    let selectedTabs = (tab.highlighted) ? await browser.tabs.query({
    2.13 +        highlighted: true,
    2.14 +        windowId: tab.windowId
    2.15 +    }) : [tab];
    2.16 +    browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id),
    2.17 +            {windowId: targetWindowId, index: -1});
    2.18  }
    2.19  
    2.20 -async function reopenTab(tab, targetWindowId) {
    2.21 -    if (!ALLOWED_PROTOCOLS.has(new URL(tab.url).protocol)) {
    2.22 -        // privileged tab URL which cannot be reopened
    2.23 +async function reopenTabs(tab, targetWindowId) {
    2.24 +    // if the current tab is part of a highlighted group then reopen the whole
    2.25 +    // group
    2.26 +    let selectedTabs = (tab.highlighted) ? await browser.tabs.query({
    2.27 +        highlighted: true,
    2.28 +        windowId: tab.windowId
    2.29 +    }) : [tab];
    2.30 +    // filter out privileged tabs which cannot be reopened
    2.31 +    selectedTabs = selectedTabs.filter(selectedTab =>
    2.32 +            ALLOWED_PROTOCOLS.has(new URL(selectedTab.url).protocol));
    2.33 +    if (selectedTabs.length === 0) {
    2.34          return;
    2.35      }
    2.36 -    await browser.tabs.create({
    2.37 -        url: tab.url,
    2.38 +
    2.39 +    await Promise.all(selectedTabs.map(selectedTab => browser.tabs.create({
    2.40 +        url: selectedTab.url,
    2.41          windowId: targetWindowId
    2.42 -    });
    2.43 -    browser.tabs.remove(tab.id);
    2.44 +    })));
    2.45 +    browser.tabs.remove(selectedTabs.map(selectedTab => selectedTab.id));
    2.46  }
    2.47  
    2.48  async function onMenuShown(info, tab)  {
    2.49 @@ -58,14 +74,14 @@
    2.50          }
    2.51          if (tab.incognito === targetWindow.incognito) {
    2.52              creatingMenus.push(createMenuItem({
    2.53 -                onclick: (info, tab) => moveTab(tab, targetWindow.id),
    2.54 +                onclick: (info, tab) => moveTabs(tab, targetWindow.id),
    2.55                  parentId: 'move-menu',
    2.56                  title: targetWindow.title
    2.57              }));
    2.58              moveMenuItems++;
    2.59          } else {
    2.60              creatingMenus.push(createMenuItem({
    2.61 -                onclick: (info, tab) => reopenTab(tab, targetWindow.id),
    2.62 +                onclick: (info, tab) => reopenTabs(tab, targetWindow.id),
    2.63                  parentId: 'reopen-menu',
    2.64                  title: targetWindow.title
    2.65              }));