Skip to content

Commit 59d5e2c

Browse files
committed
[frontend] fix tab switching
1 parent 8c7e825 commit 59d5e2c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

frontend/src/tabs.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export class Tab {
174174

175175
dragoffset: number;
176176
dragpos: number;
177+
startdragpos: number;
177178

178179
width: number;
179180
pos: number;
@@ -187,6 +188,7 @@ export class Tab {
187188
url: "puter://blank",
188189
icon: "/vite.svg",
189190
dragoffset: -1,
191+
startdragpos: -1,
190192
dragpos: -1,
191193
width: 0,
192194
pos: 0,
@@ -337,6 +339,12 @@ export const Tabs: Component<
337339
const root = getTabFromIndex(tab.id);
338340
const dragroot = root.querySelector(".dragroot") as HTMLElement;
339341

342+
let lifetimeOffset = tab.pos - tab.startdragpos;
343+
if (Math.abs(lifetimeOffset) < 20) {
344+
// TODO: arbitrary magic
345+
if (this.activetab != tab) this.activetab = tab;
346+
}
347+
340348
dragroot.style.width = "";
341349
dragroot.style.position = "unset";
342350
tab.dragoffset = -1;
@@ -355,6 +363,7 @@ export const Tabs: Component<
355363
dragroot.style.width = rect.width + "px";
356364
dragroot.style.position = "absolute";
357365
tab.dragoffset = e.clientX - rect.left;
366+
tab.startdragpos = rect.left;
358367

359368
if (tab.dragoffset < 0) throw new Error("dragoffset must be positive");
360369

0 commit comments

Comments
 (0)