Skip to content

Commit 329c07a

Browse files
committed
Close native tab group by middle click
1 parent 5916b45 commit 329c07a

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

webextensions/common/Tab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,11 +2090,11 @@ export default class Tab {
20902090
}
20912091

20922092
get sanitized() {
2093-
if (!this.tab)
2093+
if (!this.raw)
20942094
return {};
20952095

20962096
const sanitized = {
2097-
...this.tab,
2097+
...this.raw,
20982098
'$possibleInitialUrl': null,
20992099
'$TST': null,
21002100
'$exportedForAPI': null,

webextensions/common/tree-behavior.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export function getParentTabOperationBehavior(tab, { context, byInternalOperatio
117117

118118
export function getClosingTabsFromParent(tab, removeInfo = {}) {
119119
log('getClosingTabsFromParent: ', tab, removeInfo);
120+
if (tab?.$TST.isNativeTabGroup) {
121+
return tab.$TST.descendants;
122+
}
120123
const closeParentBehavior = getParentTabOperationBehavior(tab, {
121124
...removeInfo,
122125
context: Constants.kPARENT_TAB_OPERATION_CONTEXT_CLOSE,

webextensions/sidebar/mouse-event-listener.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
countMatched,
3636
configs,
3737
shouldApplyAnimation,
38+
mapAndFilter,
3839
isMacOS,
3940
} from '/common/common.js';
4041
import * as ApiTabs from '/common/api-tabs.js';
@@ -719,17 +720,20 @@ async function handleDefaultMouseUpOnTab({ lastMousedown, tab, event } = {}) {
719720
}
720721

721722
if (lastMousedown.detail.isMiddleClick) { // Ctrl-click doesn't close tab on Firefox's tab bar!
722-
log(`onMouseUp: middle click on the tab ${tab.id}: `, lastMousedown.detail.targetType);
723+
log(`onMouseUp: middle click on the tab ${tab.id}: targetType = `, lastMousedown.detail.targetType);
723724
if (lastMousedown.detail.targetType != 'tab') // ignore middle click on blank area
724725
return false;
725726
const tabs = TreeBehavior.getClosingTabsFromParent(tab, {
726727
byInternalOperation: true
727728
});
728-
Sidebar.confirmToCloseTabs(tabs.map(tab => tab.$TST.sanitized))
729+
log('tabs: ', tabs);
730+
const sanitizedTabsToClose = mapAndFilter(tabs, tab => tab.$TST.isNativeTabGroup ? undefined : tab.$TST.sanitized);
731+
log('sanitizedTabsToClose: ', sanitizedTabsToClose);
732+
Sidebar.confirmToCloseTabs(sanitizedTabsToClose)
729733
.then(async confirmed => {
730734
if (!confirmed)
731735
return;
732-
const tabIds = tabs.map(tab => tab.id);
736+
const tabIds = sanitizedTabsToClose.map(tab => tab.id);
733737
await Scroll.tryLockPosition(tabIds, Scroll.LOCK_REASON_REMOVE);
734738
BackgroundConnection.sendMessage({
735739
type: Constants.kCOMMAND_REMOVE_TABS_BY_MOUSE_OPERATION,

0 commit comments

Comments
 (0)