Skip to content

Commit b779dd4

Browse files
committed
[frontend] new tab to the right and duplicate context menus
1 parent b35150e commit b779dd4

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

frontend/src/Tab.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type SerializedTab = {
2020
history: SerializedHistory;
2121
};
2222

23-
let id = 0;
23+
let id = 100;
2424
export class Tab extends StatefulClass {
2525
id: number;
2626
title: string | null;
@@ -54,6 +54,9 @@ export class Tab extends StatefulClass {
5454
this.title = null;
5555
this.internalpage = null;
5656

57+
const frame = scramjet.createFrame();
58+
this.frame = frame;
59+
5760
this.history = new History(this);
5861
this.history.push(this.url, undefined);
5962

@@ -65,7 +68,6 @@ export class Tab extends StatefulClass {
6568
this.width = 0;
6669
this.pos = 0;
6770

68-
const frame = scramjet.createFrame();
6971
addHistoryListeners(frame, this);
7072
frame.addEventListener("contextInit", (ctx) => {
7173
injectContextMenu(ctx.client, this);
@@ -77,7 +79,6 @@ export class Tab extends StatefulClass {
7779
}
7880
});
7981

80-
this.frame = frame;
8182
this.devtoolsFrame = scramjet.createFrame();
8283
}
8384

@@ -89,7 +90,7 @@ export class Tab extends StatefulClass {
8990
};
9091
}
9192
deserialize(de: SerializedTab) {
92-
if (id >= de.id) id = de.id + 1;
93+
if (de.id >= id) id = de.id + 1;
9394
this.id = de.id;
9495
this.title = de.title;
9596
this.history.deserialize(de.history);

frontend/src/browser.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,24 @@ export class Browser extends StatefulClass {
7373
console.log(this.activetab, this.activetab.url);
7474
}
7575

76-
newTab() {
77-
let tab = new Tab();
76+
newTab(url?: URL) {
77+
let tab = new Tab(url);
7878
pushTab(tab);
7979
this.tabs = [...this.tabs, tab];
8080
this.activetab = tab;
8181
return tab;
8282
}
8383

84+
newTabRight(ref: Tab, url?: URL) {
85+
let tab = new Tab(url);
86+
pushTab(tab);
87+
let index = this.tabs.indexOf(ref);
88+
this.tabs.splice(index + 1, 0, tab);
89+
this.tabs = this.tabs;
90+
this.activetab = tab;
91+
return tab;
92+
}
93+
8494
destroyTab(tab: Tab) {
8595
this.tabs = this.tabs.filter((t) => t !== tab);
8696
console.log(this.tabs);

frontend/src/components/TabStrip.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IconButton } from "./IconButton";
1313
import type { Tab } from "../Tab";
1414
import html2canvas from "html2canvas";
1515
import { setContextMenu } from "./Menu";
16+
import { browser } from "../main";
1617

1718
export const DragTab: Component<{
1819
active: boolean;
@@ -24,19 +25,30 @@ export const DragTab: Component<{
2425
}> = function (cx) {
2526
cx.mount = () => {
2627
setContextMenu(cx.root, [
28+
{
29+
label: "New tab to the right",
30+
action: () => {
31+
browser.newTabRight(this.tab);
32+
},
33+
},
2734
{
2835
label: "Reload",
2936
action: () => {
3037
this.tab.frame.reload();
3138
},
3239
},
40+
{
41+
label: "Duplicate",
42+
action: () => {
43+
browser.newTabRight(this.tab, this.tab.url);
44+
},
45+
},
3346
{
3447
label: "Close Tab",
3548
action: () => {
3649
this.destroy();
3750
},
3851
},
39-
// TODO: mute? duplicate?
4052
]);
4153
};
4254
return (

0 commit comments

Comments
 (0)