Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7724 feat(desktop): left-align window toolbar as Back / Forward / sidebar toggle (#8859)

Jiayuan Zhang57fabfc0789b
diff --git a/apps/desktop/src/renderer/src/components/desktop-layout.test.tsx b/apps/desktop/src/renderer/src/components/desktop-layout.test.tsx
index a16c7fac43..d678cf5e46 100644
--- a/apps/desktop/src/renderer/src/components/desktop-layout.test.tsx
+++ b/apps/desktop/src/renderer/src/components/desktop-layout.test.tsx
@@ -155,13 +155,13 @@ describe("DesktopShell sidebar trigger", () => {
expect(mainTopBar).toHaveClass("transition-[padding-left]");
expect(mainTopBar).toHaveStyle({
paddingLeft:
- "max(0px, calc(256px - var(--sidebar-live-width, var(--sidebar-width))))",
+ "max(0px, calc(200px - var(--sidebar-live-width, var(--sidebar-width))))",
});
fireEvent.click(
container.querySelector('[data-slot="sidebar-trigger"]')!,
);
- expect(mainTopBar).toHaveStyle({ paddingLeft: "256px" });
+ expect(mainTopBar).toHaveStyle({ paddingLeft: "200px" });
expect(queryByRole("status", { name: /loading workspace/i })).toBeNull();
});
@@ -179,20 +179,20 @@ describe("DesktopShell sidebar trigger", () => {
"data-sidebar-state",
"expanded",
);
- expect(mainTopBar).toHaveStyle({ paddingLeft: "256px" });
+ expect(mainTopBar).toHaveStyle({ paddingLeft: "200px" });
fireEvent.click(getByRole("button", { name: "Collapse sidebar" }));
expect(getByTestId("page-content")).toHaveAttribute(
"data-sidebar-state",
"collapsed",
);
- expect(mainTopBar).toHaveStyle({ paddingLeft: "256px" });
+ expect(mainTopBar).toHaveStyle({ paddingLeft: "200px" });
fireEvent.click(getByRole("button", { name: "Expand sidebar" }));
expect(getByTestId("page-content")).toHaveAttribute(
"data-sidebar-state",
"expanded",
);
- expect(mainTopBar).toHaveStyle({ paddingLeft: "256px" });
+ expect(mainTopBar).toHaveStyle({ paddingLeft: "200px" });
});
});
diff --git a/apps/desktop/src/renderer/src/components/desktop-layout.workspace-gate.test.tsx b/apps/desktop/src/renderer/src/components/desktop-layout.workspace-gate.test.tsx
index 599795d6b6..a2770a8d64 100644
--- a/apps/desktop/src/renderer/src/components/desktop-layout.workspace-gate.test.tsx
+++ b/apps/desktop/src/renderer/src/components/desktop-layout.workspace-gate.test.tsx
@@ -171,7 +171,7 @@ describe("DesktopShell workspace gating", () => {
).toHaveLength(0);
expect(
container.querySelector('[data-slot="main-top-bar"]'),
- ).toHaveStyle({ paddingLeft: "256px" });
+ ).toHaveStyle({ paddingLeft: "200px" });
expect(
getByRole("status", { name: /loading workspace/i }),
).toBeVisible();
diff --git a/apps/desktop/src/renderer/src/components/window-toolbar.test.tsx b/apps/desktop/src/renderer/src/components/window-toolbar.test.tsx
index 40327d38d0..a1ab3c2f99 100644
--- a/apps/desktop/src/renderer/src/components/window-toolbar.test.tsx
+++ b/apps/desktop/src/renderer/src/components/window-toolbar.test.tsx
@@ -17,7 +17,6 @@ const historyState = vi.hoisted(() => ({
goToHistoryIndex: vi.fn(),
}));
-const navigationState = vi.hoisted(() => ({ push: vi.fn() }));
const sidebarState = vi.hoisted(() => ({
state: "expanded" as "expanded" | "collapsed",
isCompact: false,
@@ -27,10 +26,6 @@ vi.mock("@/hooks/use-tab-history", () => ({
useTabHistory: () => historyState,
}));
-vi.mock("@multica/views/navigation", () => ({
- useNavigation: () => navigationState,
-}));
-
vi.mock("@multica/views/layout", () => ({
useTabPresentation: (url: string, fallbackTitle?: string) => ({
visual: { kind: "icon", icon: "Inbox" },
@@ -46,12 +41,8 @@ vi.mock("@multica/ui/components/ui/sidebar", () => ({
),
}));
-const {
- WINDOW_TOOLBAR_CLEARANCE,
- WindowToolbar,
- browsingHistoryForMenu,
- historyIndicesForMenu,
-} = await import("./window-toolbar");
+const { WINDOW_TOOLBAR_CLEARANCE, WindowToolbar, historyIndicesForMenu } =
+ await import("./window-toolbar");
beforeEach(() => {
historyState.canGoBack = true;
@@ -70,7 +61,6 @@ beforeEach(() => {
historyState.goBack.mockReset();
historyState.goForward.mockReset();
historyState.goToHistoryIndex.mockReset();
- navigationState.push.mockReset();
sidebarState.state = "expanded";
sidebarState.isCompact = false;
vi.useFakeTimers();
@@ -96,62 +86,16 @@ describe("historyIndicesForMenu", () => {
});
});
-describe("browsingHistoryForMenu", () => {
- it("uses workspace browsing history across tabs and excludes the current resource", () => {
- expect(
- browsingHistoryForMenu(
- [
- { url: "/acme/issues/issue-2", title: "Issue 2" },
- { url: "/acme/issues?filter=mine", title: "Issues" },
- { url: "/acme/projects", title: "Projects" },
- ],
- "/acme/issues",
- ),
- ).toEqual([
- { url: "/acme/issues/issue-2", title: "Issue 2" },
- { url: "/acme/projects", title: "Projects" },
- ]);
- });
-
- it("excludes only the current Inbox issue while keeping other Inbox visits", () => {
- expect(
- browsingHistoryForMenu(
- [
- { url: "/acme/inbox?issue=issue-b", title: "Issue B" },
- { url: "/acme/inbox?issue=issue-a", title: "Issue A" },
- { url: "/acme/inbox", title: "Inbox" },
- { url: "/acme/projects", title: "Projects" },
- ],
- "/acme/inbox?view=archived&issue=issue-b",
- ),
- ).toEqual([
- { url: "/acme/inbox?issue=issue-a", title: "Issue A" },
- { url: "/acme/inbox", title: "Inbox" },
- { url: "/acme/projects", title: "Projects" },
- ]);
- });
-
- it("bounds the recently viewed menu to thirty entries", () => {
- const entries = Array.from(
- { length: 60 },
- (_, index) => ({
- url: `/acme/issues/issue-${index}`,
- title: `Issue ${index}`,
- }),
- );
- expect(browsingHistoryForMenu(entries, "/acme/settings")).toHaveLength(30);
- });
-});
-
describe("WindowToolbar history controls", () => {
- it("right-aligns the controls to the expanded sidebar edge", () => {
+ it("left-aligns the controls past the traffic lights across the expanded sidebar", () => {
render(<WindowToolbar />);
const toolbar = document.querySelector('[data-slot="window-toolbar"]');
- expect(toolbar).toHaveClass("justify-end");
+ expect(toolbar).not.toHaveClass("justify-end");
expect(toolbar).toHaveStyle({
+ paddingLeft: "88px",
width:
- "max(var(--sidebar-live-width, var(--sidebar-width)), 256px)",
+ "max(var(--sidebar-live-width, var(--sidebar-width)), 200px)",
});
expect(toolbar).toHaveAttribute("data-sidebar-resize-consumer");
expect(toolbar).not.toHaveClass("transition-[width]");
@@ -163,40 +107,27 @@ describe("WindowToolbar history controls", () => {
rerender(<WindowToolbar />);
const toolbar = document.querySelector('[data-slot="window-toolbar"]');
- expect(WINDOW_TOOLBAR_CLEARANCE).toBe(256);
- expect(toolbar).toHaveClass("justify-end");
- expect(toolbar).toHaveStyle({ width: "256px" });
+ expect(WINDOW_TOOLBAR_CLEARANCE).toBe(200);
+ expect(toolbar).toHaveStyle({ paddingLeft: "88px", width: "200px" });
});
- it("opens workspace browsing history and navigates the active tab to a selected entry", () => {
+ it("orders Back, Forward, then the sidebar toggle with no separate History button", () => {
render(<WindowToolbar />);
- fireEvent.click(screen.getByRole("button", { name: "History" }));
- expect(screen.getByText("Recently viewed")).toBeInTheDocument();
- expect(screen.getByTitle("MUL-1: Fix history")).toBeInTheDocument();
-
- fireEvent.click(
- screen.getByRole("menuitem", { name: "MUL-1: Fix history" }),
- );
- expect(navigationState.push).toHaveBeenCalledWith(
- "/acme/issues/issue-1",
- );
- expect(historyState.goToHistoryIndex).not.toHaveBeenCalled();
+ expect(
+ screen.getAllByRole("button").map((button) => button.getAttribute("aria-label")),
+ ).toEqual(["Go back", "Go forward", "Toggle sidebar"]);
+ expect(screen.queryByRole("button", { name: "History" })).toBeNull();
});
- it("keeps browsing history available in a fresh tab while its Back and Forward stay disabled", () => {
+ it("disables Back and Forward in a fresh tab", () => {
historyState.canGoBack = false;
historyState.canGoForward = false;
historyState.historyEntries = ["/acme/issues"];
historyState.historyIndex = 0;
- historyState.browsingHistory = [
- { url: "/acme/issues", title: "Issues" },
- { url: "/acme/issues/issue-1", title: "MUL-1: Fix history" },
- ];
render(<WindowToolbar />);
- expect(screen.getByRole("button", { name: "History" })).toBeEnabled();
expect(screen.getByRole("button", { name: "Go back" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Go forward" })).toBeDisabled();
});
diff --git a/apps/desktop/src/renderer/src/components/window-toolbar.tsx b/apps/desktop/src/renderer/src/components/window-toolbar.tsx
index 6607ca947d..a6d04797e2 100644
--- a/apps/desktop/src/renderer/src/components/window-toolbar.tsx
+++ b/apps/desktop/src/renderer/src/components/window-toolbar.tsx
@@ -6,7 +6,7 @@ import {
useState,
type PointerEventHandler,
} from "react";
-import { ChevronLeft, ChevronRight, History } from "lucide-react";
+import { ArrowLeft, ArrowRight } from "lucide-react";
import {
SidebarTrigger,
useSidebar,
@@ -22,19 +22,21 @@ import {
ResourceLeadingVisual,
useTabPresentation,
} from "@multica/views/layout";
-import { useNavigation } from "@multica/views/navigation";
-import {
- useTabHistory,
- type BrowsingHistoryEntry,
-} from "@/hooks/use-tab-history";
+import { useTabHistory } from "@/hooks/use-tab-history";
import { browsingHistoryKeyForUrl } from "@/stores/tab-store";
-export const WINDOW_TOOLBAR_CLEARANCE = 256;
+// Controls sit left-aligned just past the macOS traffic lights, which end
+// around x=76 with trafficLightPosition { x: 16 }. The clearance covers that
+// inset plus Back, Forward and the sidebar toggle (3 × 28px, 2 × 8px gaps) and
+// a 12px trailing pad, and matches the sidebar's minimum width so the
+// controls always fit inside the expanded sidebar column.
+const TRAFFIC_LIGHT_CLEARANCE = 88;
+export const WINDOW_TOOLBAR_CLEARANCE = 200;
const LONG_PRESS_DURATION_MS = 500;
const LONG_PRESS_MOVE_TOLERANCE_PX = 8;
const MAX_HISTORY_MENU_ITEMS = 30;
-type HistoryMenuMode = "all" | "back" | "forward";
+type HistoryMenuMode = "back" | "forward";
interface OpenHistoryMenu {
mode: HistoryMenuMode;
@@ -120,7 +122,7 @@ function useLongPress(
}
export function historyIndicesForMenu(
- mode: Exclude<HistoryMenuMode, "all">,
+ mode: HistoryMenuMode,
currentIndex: number,
historyLength: number,
): number[] {
@@ -141,20 +143,6 @@ export function historyIndicesForMenu(
);
}
-export function browsingHistoryForMenu(
- browsingHistory: BrowsingHistoryEntry[],
- currentUrl: string | undefined,
-): BrowsingHistoryEntry[] {
- const currentResource = currentUrl
- ? browsingHistoryKeyForUrl(currentUrl)
- : undefined;
- return browsingHistory
- .filter(
- (entry) => browsingHistoryKeyForUrl(entry.url) !== currentResource,
- )
- .slice(0, MAX_HISTORY_MENU_ITEMS);
-}
-
function HistoryMenuItem({
url,
fallbackTitle,
@@ -195,7 +183,6 @@ export function WindowToolbar() {
goForward,
goToHistoryIndex,
} = useTabHistory();
- const { push } = useNavigation();
const [menu, setMenu] = useState<OpenHistoryMenu | null>(null);
const menuAnchorRef = useRef<HTMLElement | null>(null);
const menuContentRef = useRef<HTMLDivElement | null>(null);
@@ -226,19 +213,11 @@ export function WindowToolbar() {
const menuIndices = useMemo(
() =>
- menu && menu.mode !== "all"
+ menu
? historyIndicesForMenu(menu.mode, historyIndex, historyEntries.length)
: [],
[historyEntries.length, historyIndex, menu],
);
- const browsingMenuEntries = useMemo(
- () =>
- browsingHistoryForMenu(
- browsingHistory,
- historyEntries[historyIndex],
- ),
- [browsingHistory, historyEntries, historyIndex],
- );
const browsingHistoryTitles = useMemo(
() =>
new Map(
@@ -251,11 +230,7 @@ export function WindowToolbar() {
[browsingHistory],
);
const menuLabel =
- menu?.mode === "back"
- ? "Back history"
- : menu?.mode === "forward"
- ? "Forward history"
- : "Recently viewed";
+ menu?.mode === "forward" ? "Forward history" : "Back history";
const navButtonClassName =
"flex size-7 items-center justify-center rounded-md text-faint-foreground transition-colors duration-150 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:outline-2 focus-visible:outline-offset-2 disabled:pointer-events-none disabled:opacity-30 motion-reduce:transition-none";
@@ -266,46 +241,24 @@ export function WindowToolbar() {
},
[goToHistoryIndex],
);
- const selectBrowsingHistory = useCallback(
- (url: string) => {
- push(url);
- setMenu(null);
- },
- [push],
- );
return (
<div
data-slot="window-toolbar"
data-sidebar-resize-consumer
- className="fixed left-0 top-0 z-30 flex h-12 shrink-0 items-center justify-end px-3"
+ className="fixed left-0 top-0 z-30 flex h-12 shrink-0 items-center pr-3"
style={
{
WebkitAppRegion: "drag",
width: toolbarWidth,
+ paddingLeft: TRAFFIC_LIGHT_CLEARANCE,
} as React.CSSProperties
}
>
<div
- className="flex items-center gap-1"
+ className="flex items-center gap-2"
style={{ WebkitAppRegion: "no-drag" } as React.CSSProperties}
>
- <SidebarTrigger
- className="size-7 text-faint-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
- style={{ WebkitAppRegion: "no-drag" } as React.CSSProperties}
- />
- <button
- type="button"
- disabled={browsingMenuEntries.length === 0}
- aria-label="History"
- aria-haspopup="menu"
- aria-expanded={menu?.mode === "all"}
- title="History"
- className={navButtonClassName}
- onClick={(event) => openMenu("all", event.currentTarget)}
- >
- <History aria-hidden className="size-4" />
- </button>
<button
type="button"
disabled={!canGoBack}
@@ -336,7 +289,7 @@ export function WindowToolbar() {
goBack();
}}
>
- <ChevronLeft aria-hidden className="size-4" />
+ <ArrowLeft aria-hidden className="size-4" />
</button>
<button
type="button"
@@ -368,8 +321,12 @@ export function WindowToolbar() {
goForward();
}}
>
- <ChevronRight aria-hidden className="size-4" />
+ <ArrowRight aria-hidden className="size-4" />
</button>
+ <SidebarTrigger
+ className="size-7 text-faint-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
+ style={{ WebkitAppRegion: "no-drag" } as React.CSSProperties}
+ />
</div>
<DropdownMenu
@@ -390,25 +347,16 @@ export function WindowToolbar() {
>
<DropdownMenuGroup>
<DropdownMenuLabel>{menuLabel}</DropdownMenuLabel>
- {menu?.mode === "all"
- ? browsingMenuEntries.map((entry) => (
- <HistoryMenuItem
- key={entry.url}
- url={entry.url}
- fallbackTitle={entry.title}
- onSelect={() => selectBrowsingHistory(entry.url)}
- />
- ))
- : menuIndices.map((index) => (
- <HistoryMenuItem
- key={`${index}:${historyEntries[index]}`}
- url={historyEntries[index]}
- fallbackTitle={browsingHistoryTitles.get(
- browsingHistoryKeyForUrl(historyEntries[index]),
- )}
- onSelect={() => selectHistoryIndex(index)}
- />
- ))}
+ {menuIndices.map((index) => (
+ <HistoryMenuItem
+ key={`${index}:${historyEntries[index]}`}
+ url={historyEntries[index]}
+ fallbackTitle={browsingHistoryTitles.get(
+ browsingHistoryKeyForUrl(historyEntries[index]),
+ )}
+ onSelect={() => selectHistoryIndex(index)}
+ />
+ ))}
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>