addons/firefox-addons/tab-mover
changeset 28:8279a650da6b
Preserve active and highlighted properties of moved tabs
This is consistent with the equivalent built-in drag-and-drop operations.
This is consistent with the equivalent built-in drag-and-drop operations.
author | Guido Berhoerster <guido+tab-mover@berhoerster.name> |
---|---|
date | Sat Feb 27 09:14:34 2021 +0100 (15 months ago) |
parents | a58b1c0373b5 |
children | b1b1f2737249 |
files | background.js |
line diff
1.1 --- a/background.js Wed Dec 23 10:53:28 2020 +0100 1.2 +++ b/background.js Sat Feb 27 09:14:34 2021 +0100 1.3 @@ -32,8 +32,18 @@ 1.4 highlighted: true, 1.5 windowId: tab.windowId 1.6 }) : [tab]; 1.7 - browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id), 1.8 + let activeTab = selectedTabs.find(tab => tab.active); 1.9 + await browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id), 1.10 {windowId: targetWindowId, index: -1}); 1.11 + 1.12 + // mark the previously active tab active again before highlighting other 1.13 + // tabs since this resets the selected tabs 1.14 + await browser.tabs.update(activeTab.id, {active: true}); 1.15 + for (let tab of selectedTabs) { 1.16 + if (tab.id !== activeTab.id) { 1.17 + browser.tabs.update(tab.id, {active: false, highlighted: true}); 1.18 + } 1.19 + } 1.20 } 1.21 1.22 async function reopenTabs(tab, targetWindowId) { 1.23 @@ -49,11 +59,27 @@ 1.24 if (selectedTabs.length === 0) { 1.25 return; 1.26 } 1.27 + let activeTab = selectedTabs.find(tab => tab.active); 1.28 + // the actually active tab may have been filtered out above, fall back to 1.29 + // the first highlighted one 1.30 + if (typeof activeTab === 'undefined') { 1.31 + activeTab = selectedTabs[0]; 1.32 + activeTab.active = true; 1.33 + } 1.34 1.35 - await Promise.all(selectedTabs.map(selectedTab => browser.tabs.create({ 1.36 - url: selectedTab.url, 1.37 - windowId: targetWindowId 1.38 - }))); 1.39 + let newTabs = await Promise.all(selectedTabs.map(selectedTab => { 1.40 + return browser.tabs.create({ 1.41 + url: selectedTab.url, 1.42 + windowId: targetWindowId, 1.43 + active: selectedTab.active 1.44 + }); 1.45 + })); 1.46 + // tabs can only be highlighted after they have been created 1.47 + for (let tab of newTabs) { 1.48 + if (!tab.active) { 1.49 + browser.tabs.update(tab.id, {active: false, highlighted: true}); 1.50 + } 1.51 + } 1.52 browser.tabs.remove(selectedTabs.map(selectedTab => selectedTab.id)); 1.53 } 1.54