Skip to content

Commit

Permalink
Focus to the expected in-tree tab as configured, when a last child ta…
Browse files Browse the repository at this point in the history
…b is closed after it was reopened #3559
  • Loading branch information
piroor committed May 24, 2024
1 parent 886de2a commit 3cc2a56
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion webextensions/background/successor-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import {
log as internalLogger,
dumpTab,
configs
configs,
wait,
} from '/common/common.js';
import * as ApiTabs from '/common/api-tabs.js';
import * as Constants from '/common/constants.js';
Expand Down Expand Up @@ -62,8 +63,26 @@ function setSuccessor(tabId, successorTabId = -1) {
});
mPromisedUpdatedSuccessorTabId.set(tabId, promisedUpdate);

const initialSuccessorTabId = tab.successorTabId;
browser.tabs.update(tabId, {
successorTabId
}).then(async () => {
// tabs.onUpdated listener won't be called sometimes, so this is a failsafe.
while (true) {
const promisedUpdate = mPromisedUpdatedSuccessorTabId.get(tabId);
if (!promisedUpdate)
break;

const tab = await browser.tabs.get(tabId);
if (tab.successorTabId == initialSuccessorTabId &&
tab.successorTabId != successorTabId) {
await wait(200);
continue;
}

mPromisedUpdatedSuccessorTabId.delete(tabId);
promisedUpdate.resolver(tab.successorTabId);
}
}).catch(ApiTabs.createErrorHandler(ApiTabs.handleMissingTabError, error => {
// ignore error for already closed tab
if (!error ||
Expand Down

0 comments on commit 3cc2a56

Please sign in to comment.