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.

feat(agentic-ide): split a pane in half, and let every seam be dragged

Ruben Lütked01bee536a04
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
index 4a067a58fd..ff7506743a 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
@@ -9,7 +9,14 @@
* take the identical path through the app, and the two can never behave
* differently.
*/
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import {
+ useCallback,
+ useEffect,
+ useLayoutEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import * as Dialog from "@radix-ui/react-dialog";
import {
ArrowUp,
@@ -56,6 +63,7 @@ import {
weightsAfterSplit,
type PaneBox,
type PaneSeam,
+ type PaneWeights,
} from "./paneLayout";
import { usePaneWeights } from "./usePaneWeights";
import { ContinueInterrupted } from "./ContinueInterrupted";
@@ -287,6 +295,25 @@ function seamStyle(seam: PaneSeam): React.CSSProperties {
};
}
+/**
+ * The style properties a box or a seam is positioned by, and nothing else.
+ *
+ * Written straight onto the element while a seam is being dragged, so the
+ * gesture never goes through React (see `paintDraggedLayout` and the header of
+ * `usePaneWeights`). Kept to the four that `paneBoxStyle` and `seamStyle`
+ * actually set, and blanking a missing one is what lets the same helper place
+ * both: a vertical seam has a height and no width, a horizontal one the
+ * reverse.
+ */
+const POSITION_KEYS = ["left", "top", "width", "height"] as const;
+
+function writePosition(node: HTMLElement, style: React.CSSProperties): void {
+ for (const key of POSITION_KEYS) {
+ const value = style[key];
+ node.style[key] = value === undefined ? "" : String(value);
+ }
+}
+
/*
* Terminal appearance and text size are remembered, and the appearance follows
* the app's own theme until the user says otherwise.
diff --git a/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.ts b/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.ts
index d7852fab7d..f7931a13cf 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/usePaneWeights.ts
@@ -76,6 +76,15 @@ export interface PaneWeightControls {
nudge: (seam: PaneSeam, deltaPx: number) => void;
/** Give a seam's two neighbours the same size — wire to `onDoubleClick`. */
even: (seam: PaneSeam) => void;
+ /**
+ * The weights a drag is currently at, or null when nothing is being dragged.
+ *
+ * They are NOT in `weights` on purpose (see `onPreview`) — this is how a
+ * caller that repaints during a drag recovers the in-flight sizes if React
+ * renders for some unrelated reason mid-gesture and puts the settled ones
+ * back on screen.
+ */
+ liveWeights: React.MutableRefObject<PaneWeights | null>;
}
/**
@@ -85,10 +94,29 @@ export interface PaneWeightControls {
* workspace can be resized mid-drag (a window animation, the prompt bar opening)
* and the pixels-to-weight conversion has to use the size the seam is actually
* being dragged across.
+ *
+ * ## Why a drag does not go through React
+ *
+ * `onPreview` is handed each frame's weights INSTEAD of them being put into
+ * state, and state is written exactly once, when the pointer is released.
+ *
+ * The reason is what a workspace re-render costs. Every pane in it is a live
+ * terminal with a header, a recap card and a scrollbar, and a pointer emits up
+ * to 120 moves a second — so routing a drag through state re-built the entire
+ * grid on every one of them, and a dozen panes dropped the gesture to a few
+ * frames a second. Worse, it fed back: each of those renders resized every
+ * pane's DOM box, which woke each pane's own ResizeObserver, which eventually
+ * refitted the terminal and told the agent behind it to redraw its whole screen
+ * — mid-drag, on the same thread. Painting the boxes directly costs one layout
+ * computation and N style writes per frame and does not touch React at all.
+ *
+ * A caller that passes nothing keeps the old behaviour (state per frame), which
+ * is what the keyboard path and the hook's own tests use.
*/
export function usePaneWeights(
workspaceId: string,
extent: () => WorkspaceExtent,
+ onPreview?: (weights: PaneWeights) => void,
): PaneWeightControls {
const [weights, setWeights] = useState<PaneWeights>(() => loadWeights(workspaceId));
const [dragging, setDragging] = useState<string | null>(null);
@@ -116,19 +144,25 @@ export function usePaneWeights(
from: PaneWeights;
} | null>(null);
+ /** Where the pointer is right now, and the sizes that produces. */
+ const point = useRef(0);
+ const live = useRef<PaneWeights | null>(null);
+
const weightsRef = useRef(weights);
weightsRef.current = weights;
const extentRef = useRef(extent);
extentRef.current = extent;
+ const previewRef = useRef(onPreview);
+ previewRef.current = onPreview;
+
const startDrag = useCallback((seam: PaneSeam, event: React.PointerEvent) => {
event.preventDefault();
- active.current = {
- seam,
- point: seam.orientation === "vertical" ? event.clientX : event.clientY,
- from: weightsRef.current,
- };
+ const at = seam.orientation === "vertical" ? event.clientX : event.clientY;
+ active.current = { seam, point: at, from: weightsRef.current };
+ point.current = at;
+ live.current = null;
setDragging(seam.id);
}, []);
@@ -140,19 +174,60 @@ export function usePaneWeights(
return seam.orientation === "vertical" ? size.width : size.height;
};
+ // One computation and one paint per FRAME, however many moves the pointer
+ // delivered in it. The workspace is measured here too, rather than per
+ // move, so a drag reads the layout once a frame instead of interleaving
+ // reads and writes — which is what makes a browser recompute the whole
+ // grid several times over between two frames.
+ let frame: number | undefined;
+ const apply = () => {
+ frame = undefined;
+ const drag = active.current;
+ if (!drag) return;
+ const next = dragSeam(
+ drag.from,
+ drag.seam,
+ point.current - drag.point,
+ axisPx(drag.seam),
+ );
+ live.current = next;
+ // No preview target (the keyboard path, the hook's own tests): fall back
+ // to state, which is the behaviour every caller had before.
+ if (previewRef.current) previewRef.current(next);
+ else setWeights(next);
+ };
+
const onMove = (event: PointerEvent) => {
const drag = active.current;
if (!drag) return;
- const now = drag.seam.orientation === "vertical" ? event.clientX : event.clientY;
- setWeights(dragSeam(drag.from, drag.seam, now - drag.point, axisPx(drag.seam)));
+ point.current =
+ drag.seam.orientation === "vertical" ? event.clientX : event.clientY;
+ if (frame === undefined) frame = requestAnimationFrame(apply);
};
- const onUp = () => {
+ const settle = () => {
+ // Land the last move before committing, so the sizes React is told about
+ // are the ones already on screen — otherwise a drag that ended between
+ // two frames would commit the frame before it and visibly snap back.
+ if (frame !== undefined) {
+ cancelAnimationFrame(frame);
+ apply();
+ }
+ const settled = live.current;
active.current = null;
+ live.current = null;
setDragging(null);
+ if (settled) setWeights(settled);
};
+ const onUp = () => settle();
+ // A cancelled pointer (a touch taken over by the browser, a window that
+ // lost the device) must commit too: the boxes are already painted at the
+ // dragged sizes, and leaving state behind them would put every pane back
+ // where it started on the next unrelated render.
+ const onCancel = () => settle();
window.addEventListener("pointermove", onMove);
window.addEventListener("pointerup", onUp);
+ window.addEventListener("pointercancel", onCancel);
// Lock the cursor and suppress text selection for the whole drag, so the
// pointer can wander off the 6px grip without the drag looking broken.
const previousCursor = document.body.style.cursor;
@@ -162,8 +237,10 @@ export function usePaneWeights(
document.body.style.userSelect = "none";
return () => {
+ if (frame !== undefined) cancelAnimationFrame(frame);
window.removeEventListener("pointermove", onMove);
window.removeEventListener("pointerup", onUp);
+ window.removeEventListener("pointercancel", onCancel);
document.body.style.cursor = previousCursor;
document.body.style.userSelect = previousSelect;
};
@@ -179,7 +256,7 @@ export function usePaneWeights(
setWeights((current) => evenSeam(current, seam));
}, []);
- return { weights, setWeights, dragging, startDrag, nudge, even };
+ return { weights, setWeights, dragging, startDrag, nudge, even, liveWeights: live };
}
export { KEY_STEP_PX };
diff --git a/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx b/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx
index 9a85ffb7c5..36cd18154e 100644
--- a/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx
+++ b/jarvis/ui/web/frontend/src/components/layout/PaneResizer.tsx
@@ -15,6 +15,7 @@
* 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 { forwardRef } from "react";
import { cn } from "@/lib/utils";
/** How the seam itself runs — not the axis it moves along. */
@@ -54,17 +55,28 @@ 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,
- style,
- className,
- testId,
-}: PaneResizerProps) {
+/**
+ * The ref is forwarded because a seam is not always laid out by React.
+ *
+ * A tiled workspace repaints its boxes directly during a drag — see
+ * `usePaneWeights` — and the seam being dragged has to travel with them. It is
+ * the one element in the gesture the user is actually looking at, so leaving it
+ * to a re-render would make the line lag behind the pointer holding it.
+ */
+export const PaneResizer = forwardRef<HTMLDivElement, PaneResizerProps>(function PaneResizer(
+ {
+ orientation = "vertical",
+ onPointerDown,
+ onDoubleClick,
+ onNudge,
+ active,
+ title,
+ style,
+ className,
+ testId,
+ },
+ ref,
+) {
const vertical = orientation === "vertical";
const onKeyDown = (e: React.KeyboardEvent) => {
@@ -83,6 +95,7 @@ export function PaneResizer({
return (
<div
+ ref={ref}
role="separator"
aria-orientation={orientation}
aria-label={title}
@@ -128,4 +141,4 @@ export function PaneResizer({
/>
</div>
);
-}
+});