Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

refactor(ui): make the pane splitter work on both axes

Ruben Lütkece12d15c350a
diff --git a/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx b/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx
new file mode 100644
index 0000000000..9ed129e9d2
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx
@@ -0,0 +1,112 @@
+/**
+ * The draggable seam between two panes — the one grip the whole app uses.
+ *
+ * It exists once because a splitter is mostly a set of small decisions that
+ * must not differ from screen to screen: how wide the hit target is, what the
+ * cursor turns into, whether a double-click resets, and whether the keyboard
+ * can move it at all. Two hand-rolled copies drift within a week.
+ *
+ * Two details are worth knowing:
+ *
+ * * **The seam you see is 1px; the seam you can hit is 6px.** A one-pixel
+ * target is a coordination test, not a control — so the visible line is thin
+ * and the transparent grab area around it is six times wider.
+ * * **It is reachable without a mouse.** `role="separator"` plus a tab stop and
+ * the arrow keys mean the layout can be adjusted from the keyboard, which is
+ * also the only way to recover a pane that was dragged shut on a touchpad.
+ */
+import { cn } from "@/lib/utils";
+
+/** How the seam itself runs — not the axis it moves along. */
+export type PaneResizerOrientation = "vertical" | "horizontal";
+
+export interface PaneResizerProps {
+ /** ``vertical`` = an up-and-down line between two columns (drag sideways). */
+ orientation?: PaneResizerOrientation;
+ /** Begin a drag — wire to `useResizablePane`'s ``startResize``. */
+ onPointerDown: (e: React.PointerEvent) => void;
+ /** Restore the default size — wire to ``reset``. */
+ onDoubleClick: () => void;
+ /** Keyboard equivalent of a drag, in px — wire to ``nudge``. */
+ onNudge?: (delta: number) => void;
+ /** True while a drag is in progress, so the seam can light up. */
+ active: boolean;
+ /** Hover tooltip. Also used as the accessible name. */
+ title: string;
+}
+
+/** How far one arrow-key press moves the seam. */
+const KEY_STEP_PX = 16;
+/** …and one press with Shift held, for crossing the screen quickly. */
+const KEY_STEP_COARSE_PX = 64;
+
+export function PaneResizer({
+ orientation = "vertical",
+ onPointerDown,
+ onDoubleClick,
+ onNudge,
+ active,
+ title,
+}: PaneResizerProps) {
+ const vertical = orientation === "vertical";
+
+ const onKeyDown = (e: React.KeyboardEvent) => {
+ if (!onNudge) return;
+ const step = e.shiftKey ? KEY_STEP_COARSE_PX : KEY_STEP_PX;
+ // The keys that make the pane BIGGER are the ones pointing away from it,
+ // which is the same relationship the drag has.
+ const byKey: Record<string, number> = vertical
+ ? { ArrowRight: step, ArrowLeft: -step }
+ : { ArrowUp: step, ArrowDown: -step };
+ const delta = byKey[e.key];
+ if (delta === undefined) return;
+ e.preventDefault();
+ onNudge(delta);
+ };
+
+ return (
+ <div
+ role="separator"
+ aria-orientation={orientation}
+ aria-label={title}
+ title={title}
+ tabIndex={0}
+ data-testid={`pane-resizer-${orientation}`}
+ onPointerDown={onPointerDown}
+ onDoubleClick={onDoubleClick}
+ onKeyDown={onKeyDown}
+ className={cn(
+ "group relative z-10 flex shrink-0 touch-none select-none outline-none",
+ vertical
+ ? "w-1.5 cursor-col-resize items-stretch"
+ : "h-1.5 cursor-row-resize justify-stretch",
+ )}
+ >
+ {/* The visible line — it replaces the border it sits on top of. */}
+ <span
+ aria-hidden
+ className={cn(
+ "pointer-events-none absolute transition-colors",
+ vertical
+ ? "inset-y-0 left-1/2 w-px -translate-x-1/2"
+ : "inset-x-0 top-1/2 h-px -translate-y-1/2",
+ active
+ ? "bg-primary"
+ : "bg-border group-hover:bg-primary/60 group-focus-visible:bg-primary/60",
+ )}
+ />
+ {/* A short thicker stub in the middle: without it the seam reads as a
+ plain border and nobody discovers it can be moved. */}
+ <span
+ aria-hidden
+ className={cn(
+ "pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full transition-colors",
+ vertical ? "h-8 w-[3px]" : "h-[3px] w-8",
+ active
+ ? "bg-primary"
+ : "bg-border group-hover:bg-primary/70 group-focus-visible:bg-primary/70",
+ )}
+ />
+ </div>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/hooks/useResizablePane.test.ts b/jarvis/ui/web/frontend/src/hooks/useResizablePane.test.ts
index 3f425fb51f..fe0868d520 100644
--- a/jarvis/ui/web/frontend/src/hooks/useResizablePane.test.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useResizablePane.test.ts
@@ -1,51 +1,134 @@
import { renderHook, act } from "@testing-library/react";
-import { afterEach, describe, expect, it } from "vitest";
+import { describe, expect, it, afterEach } from "vitest";
-import { clampWidth, useResizablePane } from "./useResizablePane";
+import { clampSize, useResizablePane } from "./useResizablePane";
afterEach(() => window.localStorage.clear());
-describe("clampWidth", () => {
+/**
+ * One drag, start to finish, on whichever axis the pane uses.
+ *
+ * `MouseEvent` rather than `PointerEvent` because jsdom does not ship the
+ * latter everywhere; the hook only ever reads `clientX`/`clientY`, which both
+ * carry.
+ */
+function drag(
+ pane: { startResize: (e: React.PointerEvent) => void },
+ from: { x: number; y: number },
+ to: { x: number; y: number },
+) {
+ act(() => {
+ pane.startResize({
+ clientX: from.x,
+ clientY: from.y,
+ preventDefault: () => {},
+ } as unknown as React.PointerEvent);
+ });
+ act(() => {
+ window.dispatchEvent(
+ new MouseEvent("pointermove", { clientX: to.x, clientY: to.y }),
+ );
+ });
+ act(() => {
+ window.dispatchEvent(new MouseEvent("pointerup"));
+ });
+}
+
+describe("clampSize", () => {
it("clamps below min and above max", () => {
- expect(clampWidth(50, 200, 480)).toBe(200);
- expect(clampWidth(900, 200, 480)).toBe(480);
- expect(clampWidth(300, 200, 480)).toBe(300);
+ expect(clampSize(50, 200, 480)).toBe(200);
+ expect(clampSize(900, 200, 480)).toBe(480);
+ expect(clampSize(300, 200, 480)).toBe(300);
});
- it("rounds fractional widths to whole pixels", () => {
- expect(clampWidth(300.7, 200, 480)).toBe(301);
+ it("rounds fractional sizes to whole pixels", () => {
+ expect(clampSize(300.7, 200, 480)).toBe(301);
});
it("falls back to min on NaN", () => {
- expect(clampWidth(Number.NaN, 200, 480)).toBe(200);
+ expect(clampSize(Number.NaN, 200, 480)).toBe(200);
+ });
+
+ it("lets a measured ceiling win over the floor on a tiny window", () => {
+ // A prompt bar whose max is derived from the window height can legitimately
+ // end up below its own minimum. Honouring the minimum there would overflow
+ // the frame and push the grid out of the bottom of the screen.
+ expect(clampSize(200, 120, 60)).toBe(60);
});
});
describe("useResizablePane", () => {
- const opts = { storageKey: "test.width", defaultWidth: 260, min: 200, max: 480 };
+ const opts = { storageKey: "test.size", defaultSize: 260, min: 200, max: 480 };
- it("starts at the default width when storage is empty", () => {
+ it("starts at the default size when storage is empty", () => {
const { result } = renderHook(() => useResizablePane(opts));
- expect(result.current.width).toBe(260);
+ expect(result.current.size).toBe(260);
});
- it("restores a persisted width on mount", () => {
- window.localStorage.setItem("test.width", "320");
+ it("restores a persisted size on mount", () => {
+ window.localStorage.setItem("test.size", "320");
const { result } = renderHook(() => useResizablePane(opts));
- expect(result.current.width).toBe(320);
+ expect(result.current.size).toBe(320);
});
- it("clamps an out-of-band persisted width back into the band", () => {
- window.localStorage.setItem("test.width", "9999");
+ it("clamps an out-of-band persisted size back into the band", () => {
+ window.localStorage.setItem("test.size", "9999");
const { result } = renderHook(() => useResizablePane(opts));
- expect(result.current.width).toBe(480);
+ expect(result.current.size).toBe(480);
});
it("reset() returns to the default and persists it", () => {
- window.localStorage.setItem("test.width", "300");
+ window.localStorage.setItem("test.size", "300");
const { result } = renderHook(() => useResizablePane(opts));
act(() => result.current.reset());
- expect(result.current.width).toBe(260);
- expect(window.localStorage.getItem("test.width")).toBe("260");
+ expect(result.current.size).toBe(260);
+ expect(window.localStorage.getItem("test.size")).toBe("260");
+ });
+
+ it("grows a width when the grip on its right edge is dragged right", () => {
+ const { result } = renderHook(() => useResizablePane(opts));
+ drag(result.current, { x: 260, y: 0 }, { x: 340, y: 0 });
+ expect(result.current.size).toBe(340);
+ expect(window.localStorage.getItem("test.size")).toBe("340");
+ });
+
+ it("grows a height when the grip on its TOP edge is dragged UP", () => {
+ // The inverted axis is the whole reason `handle` exists: a prompt bar sits
+ // below its seam, so the pointer travelling to a SMALLER y makes it taller.
+ const { result } = renderHook(() =>
+ useResizablePane({
+ storageKey: "test.height",
+ defaultSize: 176,
+ min: 34,
+ max: 520,
+ axis: "y",
+ handle: "start",
+ }),
+ );
+ drag(result.current, { x: 0, y: 800 }, { x: 0, y: 700 });
+ expect(result.current.size).toBe(276);
+ });
+
+ it("collapses that height when the same grip is dragged to the bottom", () => {
+ const { result } = renderHook(() =>
+ useResizablePane({
+ storageKey: "test.height",
+ defaultSize: 176,
+ min: 34,
+ max: 520,
+ axis: "y",
+ handle: "start",
+ }),
+ );
+ drag(result.current, { x: 0, y: 700 }, { x: 0, y: 1400 });
+ expect(result.current.size).toBe(34);
+ });
+
+ it("nudge() moves the seam by whole pixels and stays inside the band", () => {
+ const { result } = renderHook(() => useResizablePane(opts));
+ act(() => result.current.nudge(16));
+ expect(result.current.size).toBe(276);
+ act(() => result.current.nudge(-9999));
+ expect(result.current.size).toBe(200);
});
});
diff --git a/jarvis/ui/web/frontend/src/hooks/useResizablePane.ts b/jarvis/ui/web/frontend/src/hooks/useResizablePane.ts
index 354a3b1b41..cf817171e4 100644
--- a/jarvis/ui/web/frontend/src/hooks/useResizablePane.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useResizablePane.ts
@@ -1,79 +1,112 @@
import { useCallback, useEffect, useRef, useState } from "react";
+/** Which axis the grip travels along: ``x`` sizes a width, ``y`` a height. */
+export type ResizeAxis = "x" | "y";
+
+/**
+ * Which EDGE of the resized pane the grip sits on.
+ *
+ * It decides the sign of the drag, and getting it wrong makes a splitter feel
+ * inverted — the pane shrinks while the pointer pulls it open. A grip on the
+ * ``end`` edge (right of a sidebar, bottom of a panel) grows the pane when the
+ * pointer moves further along the axis; a grip on the ``start`` edge (top of a
+ * bottom bar) grows it when the pointer moves BACK along the axis.
+ */
+export type ResizeHandleEdge = "start" | "end";
+
export interface ResizablePaneOptions {
- /** localStorage key the settled width is persisted under. */
+ /** localStorage key the settled size is persisted under. */
storageKey: string;
- /** Width used when nothing is stored yet (px). */
- defaultWidth: number;
- /** Lower bound (px) — the pane can never get thinner than this. */
+ /** Size used when nothing is stored yet (px). */
+ defaultSize: number;
+ /** Lower bound (px) — the pane can never get smaller than this. */
min: number;
/** Upper bound (px) — keeps the pane from swallowing its neighbour. */
max: number;
+ /** Width (``x``, the default) or height (``y``). */
+ axis?: ResizeAxis;
+ /** Edge the grip sits on — see `ResizeHandleEdge`. Defaults to ``end``. */
+ handle?: ResizeHandleEdge;
}
export interface ResizablePane {
- /** Current pane width in px (already clamped). */
- width: number;
+ /** Current pane size in px along `axis` (already clamped). */
+ size: number;
/** True while the user is actively dragging the grip. */
isResizing: boolean;
/** Attach to the grip's ``onPointerDown`` to begin a drag. */
startResize: (e: React.PointerEvent) => void;
- /** Snap back to ``defaultWidth`` (wire to the grip's ``onDoubleClick``). */
+ /** Snap back to ``defaultSize`` (wire to the grip's ``onDoubleClick``). */
reset: () => void;
+ /** Move the seam by ``delta`` px — the keyboard equivalent of a drag. */
+ nudge: (delta: number) => void;
}
/**
- * Clamp a pixel width into the ``[min, max]`` band and round to a whole pixel.
+ * Clamp a pixel size into the ``[min, max]`` band and round to a whole pixel.
*
* Pulled out as a free function so the boundary maths is unit-testable without
* a DOM — the drag interaction itself is verified live in the app.
*/
-export function clampWidth(value: number, min: number, max: number): number {
+export function clampSize(value: number, min: number, max: number): number {
if (Number.isNaN(value)) return min;
+ // A caller whose max is computed from a measured container can hand us an
+ // upper bound below the lower one on a very small window. Honouring `min`
+ // there would overflow the container, so the measured ceiling wins.
+ if (max < min) return Math.round(max);
return Math.min(max, Math.max(min, Math.round(value)));
}
/**
- * Drag-to-resize state for a horizontal splitter pane.
+ * Drag-to-resize state for one splitter seam, on either axis.
*
- * The settled width is persisted to ``localStorage`` so the layout survives a
+ * The settled size is persisted to ``localStorage`` so the layout survives a
* reload. Pointer listeners live on ``window`` (not the thin grip) for the
* whole drag, which is what lets the cursor wander off the 6px handle without
* dropping the drag — the canonical splitter behaviour.
*/
export function useResizablePane({
storageKey,
- defaultWidth,
+ defaultSize,
min,
max,
+ axis = "x",
+ handle = "end",
}: ResizablePaneOptions): ResizablePane {
- const [width, setWidth] = useState<number>(() =>
- clampWidth(loadWidth(storageKey, defaultWidth), min, max),
+ const [size, setSize] = useState<number>(() =>
+ clampSize(loadSize(storageKey, defaultSize), min, max),
);
const [isResizing, setIsResizing] = useState(false);
// Drag anchors — refs so the move handler never reads a stale closure.
- const startX = useRef(0);
- const startWidth = useRef(width);
+ const startPoint = useRef(0);
+ const startSize = useRef(size);
const startResize = useCallback(
(e: React.PointerEvent) => {
e.preventDefault();
- startX.current = e.clientX;
- startWidth.current = width;
+ startPoint.current = axis === "x" ? e.clientX : e.clientY;
+ startSize.current = size;
setIsResizing(true);
},
- [width],
+ [axis, size],
);
- const reset = useCallback(() => setWidth(defaultWidth), [defaultWidth]);
+ const reset = useCallback(() => setSize(defaultSize), [defaultSize]);
+
+ const nudge = useCallback(
+ (delta: number) => setSize((current) => clampSize(current + delta, min, max)),
+ [min, max],
+ );
// Global pointer listeners are armed only while dragging.
useEffect(() => {
if (!isResizing) return;
const onMove = (e: PointerEvent) => {
- setWidth(clampWidth(startWidth.current + (e.clientX - startX.current), min, max));
+ const travelled = (axis === "x" ? e.clientX : e.clientY) - startPoint.current;
+ const grown = handle === "end" ? travelled : -travelled;
+ setSize(clampSize(startSize.current + grown, min, max));
};
const onUp = () => setIsResizing(false);
@@ -82,7 +115,7 @@ export function useResizablePane({
// Lock the cursor + suppress text selection window-wide during the drag.
const prevCursor = document.body.style.cursor;
const prevSelect = document.body.style.userSelect;
- document.body.style.cursor = "col-resize";
+ document.body.style.cursor = axis === "x" ? "col-resize" : "row-resize";
document.body.style.userSelect = "none";
return () => {
@@ -91,23 +124,23 @@ export function useResizablePane({
document.body.style.cursor = prevCursor;
document.body.style.userSelect = prevSelect;
};
- }, [isResizing, min, max]);
+ }, [isResizing, min, max, axis, handle]);
- // Persist only the settled width (on mount + after each drag ends), not every
+ // Persist only the settled size (on mount + after each drag ends), not every
// intermediate drag frame — avoids hammering localStorage on pointermove.
useEffect(() => {
if (isResizing) return;
try {
- window.localStorage.setItem(storageKey, String(width));
+ window.localStorage.setItem(storageKey, String(size));
} catch {
- /* quota / private mode — pane width is non-critical, ignore */
+ /* quota / private mode — pane size is non-critical, ignore */
}
- }, [width, isResizing, storageKey]);
+ }, [size, isResizing, storageKey]);
- return { width, isResizing, startResize, reset };
+ return { size, isResizing, startResize, reset, nudge };
}
-function loadWidth(key: string, fallback: number): number {
+function loadSize(key: string, fallback: number): number {
try {
const raw = window.localStorage.getItem(key);
if (!raw) return fallback;
diff --git a/jarvis/ui/web/frontend/src/views/ChatsView.tsx b/jarvis/ui/web/frontend/src/views/ChatsView.tsx
index 1513996e15..ab0135037e 100644
--- a/jarvis/ui/web/frontend/src/views/ChatsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/ChatsView.tsx
@@ -13,6 +13,7 @@ import { ThinkingTrace, ThoughtTraceDisclosure } from "@/components/ThinkingTrac
import { cn } from "@/lib/utils";
import { useT } from "@/i18n";
import { useResizablePane } from "@/hooks/useResizablePane";
+import { PaneResizer } from "@/components/layout/PaneResizer";
import { useVoiceReadiness } from "@/hooks/useVoiceReadiness";
import {
ChatsApiError,
@@ -42,7 +43,7 @@ export function ChatsView() {
// bounds keep it from collapsing or swallowing the chat column.
const listPane = useResizablePane({
storageKey: "chats.listWidth.v1",
- defaultWidth: 260,
+ defaultSize: 260,
min: 200,
max: 560,
});
@@ -119,7 +120,7 @@ export function ChatsView() {
return (
<div className="flex h-full min-h-0">
<ConversationList
- width={listPane.width}
+ width={listPane.size}
conversations={conversations}
activeId={activeThreadId}
onOpen={openConversation}
@@ -130,7 +131,9 @@ export function ChatsView() {
<PaneResizer
onPointerDown={listPane.startResize}
onDoubleClick={listPane.reset}
+ onNudge={listPane.nudge}
active={listPane.isResizing}
+ title={t("chats_view.resize_hint")}
/>
<div className="flex min-w-0 flex-1 flex-col">
@@ -256,43 +259,6 @@ function ConversationList({
);
}
-/**
- * Vertical drag handle between the history list and the chat column.
- *
- * The visible seam is a 1px line (matching the old ``border-r``), but the hit
- * target is a wider 6px column so the grip is easy to catch. It lights up gold
- * on hover and while dragging. ``role="separator"`` keeps it accessible.
- */
-function PaneResizer({
- onPointerDown,
- onDoubleClick,
- active,
-}: {
- onPointerDown: (e: React.PointerEvent) => void;
- onDoubleClick: () => void;
- active: boolean;
-}) {
- const t = useT();
- return (
- <div
- role="separator"
- aria-orientation="vertical"
- title={t("chats_view.resize_hint")}
- onPointerDown={onPointerDown}
- onDoubleClick={onDoubleClick}
- className="group relative z-10 flex w-1.5 shrink-0 cursor-col-resize touch-none select-none items-stretch"
- >
- <span
- aria-hidden
- className={cn(
- "pointer-events-none absolute inset-y-0 left-1/2 w-px -translate-x-1/2 transition-colors",
- active ? "bg-primary" : "bg-border group-hover:bg-primary/60",
- )}
- />
- </div>
- );
-}
-
function ConversationRow({
conversation,
active,