comparison background.js @ 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 8279a650da6b
children
comparison
equal deleted inserted replaced
31:e22195f84c6d 32:aaed574396b8
31 let selectedTabs = (tab.highlighted) ? await browser.tabs.query({ 31 let selectedTabs = (tab.highlighted) ? await browser.tabs.query({
32 highlighted: true, 32 highlighted: true,
33 windowId: tab.windowId 33 windowId: tab.windowId
34 }) : [tab]; 34 }) : [tab];
35 let activeTab = selectedTabs.find(tab => tab.active); 35 let activeTab = selectedTabs.find(tab => tab.active);
36
37 // unpin tabs before moving, this matches the built-in behavior
38 let unpinningTabs = selectedTabs.flatMap(tab =>
39 tab.pinned ? [browser.tabs.update(tab.id, {pinned: false})] : []);
40 await Promise.all(unpinningTabs.map(p => p.catch(e => e)));
41
36 await browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id), 42 await browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id),
37 {windowId: targetWindowId, index: -1}); 43 {windowId: targetWindowId, index: -1});
38 44
39 // mark the previously active tab active again before highlighting other 45 // mark the previously active tab active again before highlighting other
40 // tabs since this resets the selected tabs 46 // tabs since this resets the selected tabs
41 await browser.tabs.update(activeTab.id, {active: true}); 47 await browser.tabs.update(activeTab.id, {active: true});
42 for (let tab of selectedTabs) { 48 for (let tab of selectedTabs) {
43 if (tab.id !== activeTab.id) { 49 if (typeof activeTab === 'undefined' || tab.id !== activeTab.id) {
44 browser.tabs.update(tab.id, {active: false, highlighted: true}); 50 browser.tabs.update(tab.id, {active: false, highlighted: true});
45 } 51 }
46 } 52 }
47 } 53 }
48 54