Skip to content

Commit e6704d5

Browse files
committed
chore: tabs: pass the flag fromNewTabButton in a consistent manner
1 parent e3d678f commit e6704d5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/services/tabs.fg.create.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function createTabInPanel(panel: Panel, conf?: browser.tabs.CreateP
9898

9999
const tabShell = { fromNewTabButton: true } as Tab
100100
let index = Tabs.getIndexForNewTab(panel, tabShell)
101-
const parentId = Tabs.getParentForNewTab(panel, true)
101+
const parentId = Tabs.getParentForNewTab(panel, tabShell)
102102
if (!Utils.isTabsPanel(panel)) return
103103
if (index === undefined && panel.nextTabIndex > -1) index = panel.nextTabIndex
104104

@@ -803,18 +803,21 @@ function getIndexForNewTabOtherCases(
803803
return fallbackIndex
804804
}
805805

806+
interface ParentForNewTabConf {
807+
openerTabId?: ID
808+
fromNewTabButton?: boolean
809+
}
810+
806811
/**
807812
* Find and return parent id
808813
*/
809-
export function getParentForNewTab(
810-
panel: Panel,
811-
fromNewTabButton: boolean,
812-
openerTabId?: ID
813-
): ID | undefined {
814+
export function getParentForNewTab(panel: Panel, conf?: ParentForNewTabConf): ID | undefined {
814815
const activeTab = Tabs.byId[Tabs.activeId]
815816

817+
const openerTabId = conf && conf.openerTabId
816818
let parent: Tab | undefined
817819
if (openerTabId) parent = Tabs.byId[openerTabId]
820+
const fromNewTabButton = conf ? conf.fromNewTabButton : false
818821

819822
// Place new tab opened from pinned tab
820823
if (parent && parent.pinned) return

src/services/tabs.fg.handlers.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ function onTabCreated(nativeTab: NativeTab, attached?: boolean): void {
392392
index = Tabs.getIndexForNewTab(panel, tab)
393393
if (!autoGroupTab) {
394394
if (!Settings.state.groupOnOpen) tab.openerTabId = undefined
395-
else tab.openerTabId = Tabs.getParentForNewTab(panel, false, tab.openerTabId)
395+
else {
396+
const tabShell = { openerTabId: tab.openerTabId, fromNewTabButton: true } as Tab
397+
tab.openerTabId = Tabs.getParentForNewTab(panel, tabShell)
398+
}
396399
}
397400
}
398401
}

0 commit comments

Comments
 (0)