Skip to content

Commit 2d9a735

Browse files
authored
[chrome] add more close options to tab context menus (#72)
1 parent 6e93b67 commit 2d9a735

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

packages/chrome/src/components/TabStrip/DragTab.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { css, type FC } from "dreamland/core";
22
import type { Tab } from "../../Tab/Tab";
33
import { setContextMenu } from "@components/Menu";
4-
import { iconClose, iconDuplicate, iconNew, iconRefresh } from "../../icons";
4+
import {
5+
iconClose,
6+
iconDuplicate,
7+
iconNew,
8+
iconRefresh,
9+
iconTrash,
10+
iconCloseCircle,
11+
} from "../../icons";
512
import { Icon } from "@components/Icon";
613
import { tabsService } from "../..";
714

@@ -48,12 +55,26 @@ export function DragTab(
4855
},
4956
},
5057
{
51-
label: "Close Tab",
58+
label: "Close",
5259
icon: iconClose,
5360
action: () => {
5461
this.destroy();
5562
},
5663
},
64+
{
65+
label: "Close other tabs",
66+
icon: iconTrash,
67+
action: () => {
68+
tabsService.closeOtherTabs(this.tab);
69+
},
70+
},
71+
{
72+
label: "Close tabs to the right",
73+
icon: iconCloseCircle,
74+
action: () => {
75+
tabsService.closeTabsToRight(this.tab);
76+
},
77+
},
5778
]);
5879

5980
// Open-tab animation: expands the tab container from width 0 to full computed width.

packages/chrome/src/icons.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export { default as iconTrash } from "@ktibow/iconset-ion/trash-outline";
3030

3131
export { default as iconClose } from "@ktibow/iconset-ion/close";
3232
export { default as iconCloseOutline } from "@ktibow/iconset-ion/close-outline";
33+
export { default as iconCloseCircle } from "@ktibow/iconset-ion/close-circle-outline";
3334

3435
export { default as iconFolder } from "@ktibow/iconset-ion/folder-outline";
3536
export { default as iconPause } from "@ktibow/iconset-ion/pause-outline";

packages/chrome/src/services/TabsService.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ export class TabsService extends Service {
7878
return tab;
7979
}
8080

81+
closeTabsToRight(ref: Tab) {
82+
let index = this.tabs.indexOf(ref);
83+
let toClose = this.tabs.slice(index + 1);
84+
toClose.forEach((tab) => {
85+
this.destroyTab(tab);
86+
});
87+
}
88+
89+
closeOtherTabs(ref: Tab) {
90+
let toClose = this.tabs.filter((tab) => tab !== ref);
91+
toClose.forEach((tab) => {
92+
this.destroyTab(tab);
93+
});
94+
}
95+
8196
destroyTab(tab: Tab) {
8297
this.disown(tab);
8398
this.tabs = this.tabs.filter((t) => t !== tab);

0 commit comments

Comments
 (0)