# HG changeset patch # User Guido Berhoerster # Date 1614413674 -3600 # Node ID 8279a650da6b2cec83f23ff747e8c8647bd593c0 # Parent a58b1c0373b5b5139c1b2d435dafbae892798542 Preserve active and highlighted properties of moved tabs This is consistent with the equivalent built-in drag-and-drop operations. diff -r a58b1c0373b5 -r 8279a650da6b background.js --- a/background.js Wed Dec 23 10:53:28 2020 +0100 +++ b/background.js Sat Feb 27 09:14:34 2021 +0100 @@ -32,8 +32,18 @@ highlighted: true, windowId: tab.windowId }) : [tab]; - browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id), + let activeTab = selectedTabs.find(tab => tab.active); + await browser.tabs.move(selectedTabs.map(selectedTab => selectedTab.id), {windowId: targetWindowId, index: -1}); + + // mark the previously active tab active again before highlighting other + // tabs since this resets the selected tabs + await browser.tabs.update(activeTab.id, {active: true}); + for (let tab of selectedTabs) { + if (tab.id !== activeTab.id) { + browser.tabs.update(tab.id, {active: false, highlighted: true}); + } + } } async function reopenTabs(tab, targetWindowId) { @@ -49,11 +59,27 @@ if (selectedTabs.length === 0) { return; } + let activeTab = selectedTabs.find(tab => tab.active); + // the actually active tab may have been filtered out above, fall back to + // the first highlighted one + if (typeof activeTab === 'undefined') { + activeTab = selectedTabs[0]; + activeTab.active = true; + } - await Promise.all(selectedTabs.map(selectedTab => browser.tabs.create({ - url: selectedTab.url, - windowId: targetWindowId - }))); + let newTabs = await Promise.all(selectedTabs.map(selectedTab => { + return browser.tabs.create({ + url: selectedTab.url, + windowId: targetWindowId, + active: selectedTab.active + }); + })); + // tabs can only be highlighted after they have been created + for (let tab of newTabs) { + if (!tab.active) { + browser.tabs.update(tab.id, {active: false, highlighted: true}); + } + } browser.tabs.remove(selectedTabs.map(selectedTab => selectedTab.id)); }