comparison background.js @ 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, 25 Nov 2018 13:53:02 +0100
parents 4704e5216412
children 8279a650da6b
comparison
equal deleted inserted replaced
23:4704e5216412 24:f418a6305f17
23 } 23 }
24 }); 24 });
25 }); 25 });
26 } 26 }
27 27
28 async function moveTab(tab, targetWindowId) { 28 async function moveTabs(tab, targetWindowId) {
29 browser.tabs.move(tab.id, {windowId: targetWindowId, index: -1}); 29 // if the current tab is part of a highlighted group then move the whole
30 // group
31 let selectedTabs = (tab.highlighted) ? await browser.tabs.query({
32 highlighted: true,
33 windowId: tab.windowId
34 }) : [tab];
35 browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id),
36 {windowId: targetWindowId, index: -1});
30 } 37 }
31 38
32 async function reopenTab(tab, targetWindowId) { 39 async function reopenTabs(tab, targetWindowId) {
33 if (!ALLOWED_PROTOCOLS.has(new URL(tab.url).protocol)) { 40 // if the current tab is part of a highlighted group then reopen the whole
34 // privileged tab URL which cannot be reopened 41 // group
42 let selectedTabs = (tab.highlighted) ? await browser.tabs.query({
43 highlighted: true,
44 windowId: tab.windowId
45 }) : [tab];
46 // filter out privileged tabs which cannot be reopened
47 selectedTabs = selectedTabs.filter(selectedTab =>
48 ALLOWED_PROTOCOLS.has(new URL(selectedTab.url).protocol));
49 if (selectedTabs.length === 0) {
35 return; 50 return;
36 } 51 }
37 await browser.tabs.create({ 52
38 url: tab.url, 53 await Promise.all(selectedTabs.map(selectedTab => browser.tabs.create({
54 url: selectedTab.url,
39 windowId: targetWindowId 55 windowId: targetWindowId
40 }); 56 })));
41 browser.tabs.remove(tab.id); 57 browser.tabs.remove(selectedTabs.map(selectedTab => selectedTab.id));
42 } 58 }
43 59
44 async function onMenuShown(info, tab) { 60 async function onMenuShown(info, tab) {
45 let menuInstanceId = nextMenuInstanceId++; 61 let menuInstanceId = nextMenuInstanceId++;
46 lastMenuInstanceId = menuInstanceId; 62 lastMenuInstanceId = menuInstanceId;
56 // ignore active window 72 // ignore active window
57 continue; 73 continue;
58 } 74 }
59 if (tab.incognito === targetWindow.incognito) { 75 if (tab.incognito === targetWindow.incognito) {
60 creatingMenus.push(createMenuItem({ 76 creatingMenus.push(createMenuItem({
61 onclick: (info, tab) => moveTab(tab, targetWindow.id), 77 onclick: (info, tab) => moveTabs(tab, targetWindow.id),
62 parentId: 'move-menu', 78 parentId: 'move-menu',
63 title: targetWindow.title 79 title: targetWindow.title
64 })); 80 }));
65 moveMenuItems++; 81 moveMenuItems++;
66 } else { 82 } else {
67 creatingMenus.push(createMenuItem({ 83 creatingMenus.push(createMenuItem({
68 onclick: (info, tab) => reopenTab(tab, targetWindow.id), 84 onclick: (info, tab) => reopenTabs(tab, targetWindow.id),
69 parentId: 'reopen-menu', 85 parentId: 'reopen-menu',
70 title: targetWindow.title 86 title: targetWindow.title
71 })); 87 }));
72 reopenMenuItems++; 88 reopenMenuItems++;
73 } 89 }