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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(ide): drag the boundaries between terminal panes again
rubenluetke10-beep1c469b419764
diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.test.tsxindex c6cde2eae7..63900509db 100644--- a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.test.tsx@@ -2,8 +2,8 @@ import { useState } from "react";import { afterEach, beforeEach, expect, it, vi } from "vitest";import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";import type { SessionState } from "@/lib/agenticIdeApi";-const api = vi.hoisted(() => ({ move: vi.fn(), rename: vi.fn(), toast: vi.fn() }));-vi.mock("@/lib/agenticIdeApi", () => ({ moveTerminal: api.move, renameTerminal: api.rename }));+const api = vi.hoisted(() => ({ move: vi.fn(), rename: vi.fn(), toast: vi.fn(), weights: vi.fn() }));+vi.mock("@/lib/agenticIdeApi", () => ({ moveTerminal: api.move, renameTerminal: api.rename, saveLayoutWeights: api.weights }));vi.mock("@/store/events", () => ({ useEventStore: (select: (state: unknown) => unknown) => select({ pushToast: api.toast }) }));vi.mock("./AgenticTerminal", () => ({ AgenticTerminal: (props: {name: string; onToggleMaximize: () => void; onRestart: () => void; restartToken: number;@@ -199,3 +199,30 @@ it("ignores a spotlight aimed at another workspace", () => {expect(document.querySelector("[data-spotlit]")).toBeNull();useIdeSidePanelStore.setState({ spotlight: null });});++it("drags the seam between two panes to resize them and saves the new sizes", async () => {+ vi.useFakeTimers();+ try {+ api.weights.mockResolvedValue(makeSession());+ render(<WorkspaceTerminalGrid {...props} session={makeSession()} />);+ const canvas = document.querySelector<HTMLElement>('[data-session-id="T1"]')!.parentElement!;+ Object.defineProperty(canvas, "clientWidth", { configurable: true, value: 1000 });+ Object.defineProperty(canvas, "clientHeight", { configurable: true, value: 800 });+ // The balanced four-pane grid is two rows of two; "0:1" divides T1 | T2.+ const seam = screen.getByTestId("pane-seam-0:1");+ fireEvent.pointerDown(seam, { button: 0, pointerId: 1, clientX: 500, clientY: 100 });+ fireEvent.pointerMove(window, { pointerId: 1, clientX: 700, clientY: 100 });+ fireEvent.pointerUp(window, { pointerId: 1, clientX: 700, clientY: 100 });+ expect(document.querySelector<HTMLElement>('[data-session-id="T1"]')!.style.width).toContain("70%");+ expect(document.querySelector<HTMLElement>('[data-session-id="T3"]')!.style.width).toContain("50%");+ await act(async () => { vi.advanceTimersByTime(1000); });+ expect(api.weights).toHaveBeenCalledTimes(1);+ } finally { vi.useRealTimers(); }+});++it("hides the seams while a pane is maximized", () => {+ render(<WorkspaceTerminalGrid {...props} session={makeSession()} />);+ expect(screen.getAllByRole("separator").length).toBe(3);+ fireEvent.click(screen.getByRole("button", { name: "Maximize T1" }));+ expect(screen.queryAllByRole("separator")).toHaveLength(0);+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsxindex fd26a35f24..3bae73ca08 100644--- a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceTerminalGrid.tsx@@ -1,4 +1,4 @@-import { useCallback, useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";import { AgenticTerminal } from "./AgenticTerminal";import { AgentMark } from "./AgentMark";import { ForkPaneDialog, type ForkMode, type ForkSource } from "./ForkPaneDialog";@@ -10,13 +10,31 @@ import { useThemeValue } from "@/hooks/useTheme";import { useEventStore } from "@/store/events";import { useIdeSidePanelStore } from "@/store/ideSidePanel";import { cn } from "@/lib/utils";-import { treeLayout, treeLeaves, type LayoutNode } from "./treeLayout";+import { PaneResizer } from "@/components/layout/PaneResizer";+import { treeLayout, treeLeaves, type LayoutNode, type PaneSeam } from "./treeLayout";+import { useTreeSizes } from "./useTreeSizes";import { DOCK_LABELS, GRID_LIMIT_HINT, MAX_GRID_COLUMNS, MAX_GRID_ROWS, MAX_WORKSPACE_PANES, dockPosition, fitsWorkspace, layoutSpan, paneStyle, previewDock, workspaceLayout } from "./workspaceDocking";const GAP = 8;const MIN_WIDTH = 280;const idOf = (terminal: TerminalState) => terminal.history_id ?? terminal.key;+/*+ * A seam's grab area fills the whole gap between two panes, centred on the+ * boundary, and runs the full length of the boundary it divides.+ */+function seamStyle(seam: PaneSeam): React.CSSProperties {+ return seam.orientation === "vertical"+ ? { position: "absolute", left: `calc(${seam.x * 100}% - ${GAP / 2}px)`, top: `${seam.y * 100}%`, width: `${GAP}px`, height: `${seam.h * 100}%` }+ : { position: "absolute", top: `calc(${seam.y * 100}% - ${GAP / 2}px)`, left: `${seam.x * 100}%`, height: `${GAP}px`, width: `${seam.w * 100}%` };+}++function writeStyle(node: HTMLElement, style: React.CSSProperties) {+ for (const [property, value] of Object.entries(style)) {+ (node.style as unknown as Record<string, string>)[property] = String(value);+ }+}+interface Props {session: SessionState;onChanged: (session: SessionState) => void;@@ -63,9 +81,36 @@ export function WorkspaceTerminalGrid({ session, onChanged, onAdd, onClose, onSeconst keys = session.terminals.map((terminal) => terminal.key);const pendingKeys = treeLeaves(optimistic);const pendingOrderMatches = optimistic && pendingKeys.length === keys.length && pendingKeys.every((key) => keys.includes(key));- const tree = pendingOrderMatches ? optimistic : workspaceLayout(session.layout, session.terminals);const tiles = session.terminals;+ const canvas = useRef<HTMLDivElement>(null);+ const paneNodes = useRef(new Map<string, HTMLElement>());+ const seamNodes = useRef(new Map<string, HTMLElement>());+ /*+ * A seam drag repaints the boxes directly, once per frame, instead of+ * re-rendering every live terminal per pointer move; state is written once+ * on release (see `useTreeSizes`).+ */+ const paintDragged = useCallback((next: LayoutNode) => {+ const terminals = latest.current.session.terminals;+ const live = treeLayout(next, terminals);+ terminals.forEach((terminal, index) => {+ const node = paneNodes.current.get(idOf(terminal));+ const box = live.boxes[index];+ if (node && box) writeStyle(node, paneStyle(box));+ });+ for (const seam of live.seams) {+ const node = seamNodes.current.get(seam.id);+ if (node) writeStyle(node, seamStyle(seam));+ }+ }, []);+ const sizes = useTreeSizes(+ workspaceLayout(session.layout, session.terminals),+ useCallback(() => ({ width: canvas.current?.clientWidth ?? 0, height: canvas.current?.clientHeight ?? 0 }), []),+ paintDragged,+ );+ const tree = pendingOrderMatches ? optimistic : sizes.tree;const layout = treeLayout(tree, tiles);+ const resizing = sizes.dragging !== null;const columns = Math.max(1, layoutSpan(tree, "row"));const visibleMaximized = maximized && members.includes(maximized) ? maximized : null;@@ -258,6 +303,14 @@ export function WorkspaceTerminalGrid({ session, onChanged, onAdd, onClose, onSe};const computerName = (terminal: TerminalState) => terminal.computer_id? (computers.find((computer) => computer.id === terminal.computer_id)?.name ?? "another computer") : undefined;+ // Any other render mid-drag (a poll, a pane going live) would paint the+ // pre-drag sizes; re-apply the in-flight layout right after it.+ useLayoutEffect(() => {+ if (sizes.dragging === null) return;+ const inFlight = sizes.liveTree.current;+ if (inFlight) paintDragged(inFlight);+ });+ const showSeams = !visibleMaximized && !drag && !saving && !disabled && !optimistic && tiles.length > 1;const dragged = drag ? session.terminals.find((terminal) => idOf(terminal) === drag.id) : null;// A pane picked from the side panel may sit off-screen on a narrow grid.@@ -270,13 +323,13 @@ export function WorkspaceTerminalGrid({ session, onChanged, onAdd, onClose, onSe}, [spotlitPane]);return <div ref={frame} data-testid="workspace-terminal-grid" aria-busy={saving} className="relative h-full min-h-0 overflow-auto p-2">- <div className="relative h-full" style={{+ <div ref={canvas} className={cn("relative h-full", resizing && "select-none")} style={{minWidth: visibleMaximized ? undefined : `${columns * MIN_WIDTH + (columns - 1) * GAP}px`,minHeight: visibleMaximized ? "240px" : `${Math.max(1, layoutSpan(tree, "column")) * 200}px`,}}>{tiles.map((terminal, index) => {const id = idOf(terminal);- return <div key={id} data-session-id={id} data-spotlit={spotlitPane === terminal.name ? "true" : undefined} tabIndex={0}+ return <div key={id} ref={(node) => { if (node) paneNodes.current.set(id, node); else paneNodes.current.delete(id); }} data-session-id={id} data-spotlit={spotlitPane === terminal.name ? "true" : undefined} tabIndex={0}aria-label={`${terminal.name}. Drag to an edge to dock, or the center to swap. Alt+Arrow swaps with a neighbor.`}onKeyDown={(event) => {if (event.target !== event.currentTarget && !(event.target instanceof HTMLElement && event.target.closest("[data-ide-drag-handle]"))) return;@@ -309,6 +362,7 @@ export function WorkspaceTerminalGrid({ session, onChanged, onAdd, onClose, onSename={terminal.name} workspaceId={session.id} displayName={terminal.display_name}recap={terminal.recap} promptCount={terminal.prompts_sent} appearance={appearance ?? theme} fontSize={fontSize}focused={selected === terminal.name} onFocus={() => { if (spotlitPane && spotlitPane !== terminal.name) setSpotlight(null); onSelect(terminal.name); }}+ layoutBusy={resizing}maximized={visibleMaximized === id} onToggleMaximize={() => setMaximized((current) => current === id ? null : id)}onArrangeStart={visibleMaximized || saving || disabled ? undefined : (event) => startDrag(id, event)} arranging={drag?.id === id}onClose={() => onClose(terminal)} onAttachError={(message) => pushToast("error", message)}@@ -325,6 +379,23 @@ export function WorkspaceTerminalGrid({ session, onChanged, onAdd, onClose, onSe</div>}</div>;})}+ {/*+ The boundaries between panes: drag one to give the panes on either side+ more or less room, double-click it to even them out, or focus it and+ use the arrow keys. Only the panes it divides change size.+ */}+ {showSeams && layout.seams.map((seam) => (+ <PaneResizer key={seam.id}+ ref={(node) => { if (node) seamNodes.current.set(seam.id, node); else seamNodes.current.delete(seam.id); }}+ testId={`pane-seam-${seam.id}`} orientation={seam.orientation} title={seam.label}+ active={sizes.dragging === seam.id}+ onPointerDown={(event) => { if (event.button === 0) sizes.startDrag(seam, event); }}+ onDoubleClick={() => sizes.even(seam)}+ // PaneResizer's vertical sign is written for a pane's own edge; here+ // an arrow key moves the seam the way it points.+ onNudge={(delta) => sizes.nudge(seam, seam.orientation === "horizontal" ? -delta : delta)}+ className="!z-30" style={seamStyle(seam)} />+ ))}</div>{drag && dragged && <div aria-hidden="true" className="pointer-events-none fixed z-[100] flex items-center gap-2 rounded-lg border border-border bg-popover px-3 py-2 text-sm font-medium text-popover-foreground shadow-xl"style={{ left: drag.x + 14, top: drag.y + 14 }}>diff --git a/jarvis/ui/web/frontend/src/components/agentic/useTreeSizes.ts b/jarvis/ui/web/frontend/src/components/agentic/useTreeSizes.tsindex 2a897ea101..1b310d7883 100644--- a/jarvis/ui/web/frontend/src/components/agentic/useTreeSizes.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/useTreeSizes.ts@@ -146,89 +146,98 @@ export function useTreeSizes(const previewRef = useRef(onPreview);previewRef.current = onPreview;- const startDrag = useCallback((seam: PaneSeam, event: React.PointerEvent) => {- const from = treeRef.current;- if (!from) return;- event.preventDefault();- const at = seam.orientation === "vertical" ? event.clientX : event.clientY;- active.current = { seam, point: at, from };- point.current = at;- live.current = null;- setDragging(seam.id);- }, []);+ /** Tears down the gesture in flight, if any; set while a drag runs. */+ const stopDrag = useRef<(() => void) | null>(null);++ /*+ * The window listeners are attached HERE, synchronously, not in an effect+ * that runs after the next render. A quick gesture — or a pointer driven by+ * automation — can deliver its moves and its release before that render,+ * and a listener that arrives late misses the whole drag and leaves the seam+ * stuck "dragging" until some unrelated release somewhere else.+ */+ const startDrag = useCallback(+ (seam: PaneSeam, event: React.PointerEvent) => {+ const from = treeRef.current;+ if (!from) return;+ event.preventDefault();+ stopDrag.current?.();+ const at = seam.orientation === "vertical" ? event.clientX : event.clientY;+ active.current = { seam, point: at, from };+ point.current = at;+ live.current = null;+ setDragging(seam.id);- useEffect(() => {- if (!dragging) return;+ const axisPx = () => {+ const size = extentRef.current();+ return seam.orientation === "vertical" ? size.width : size.height;+ };- const axisPx = (seam: PaneSeam) => {- const size = extentRef.current();- return seam.orientation === "vertical" ? size.width : size.height;- };+ // One computation and one paint per FRAME, however many moves the+ // pointer delivered in it.+ 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());+ live.current = next;+ if (previewRef.current) previewRef.current(next);+ else commit(next);+ };- // One computation and one paint per FRAME, however many moves the pointer- // delivered in it.- 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;- if (previewRef.current) previewRef.current(next);- else commit(next);- };+ const onMove = (move: PointerEvent) => {+ if (!active.current) return;+ point.current = seam.orientation === "vertical" ? move.clientX : move.clientY;+ if (frame === undefined) frame = requestAnimationFrame(apply);+ };- const onMove = (event: PointerEvent) => {- const drag = active.current;- if (!drag) return;- point.current =- drag.seam.orientation === "vertical" ? event.clientX : event.clientY;- if (frame === undefined) frame = requestAnimationFrame(apply);- };- const settle = () => {- // Land the last move before committing, so the sizes React is told- // about are the ones already on screen.- if (frame !== undefined) {- cancelAnimationFrame(frame);- apply();+ // Lock the cursor and suppress text selection for the whole drag, so the+ // pointer can wander off the thin grip without the drag looking broken.+ const previousCursor = document.body.style.cursor;+ const previousSelect = document.body.style.userSelect;+ document.body.style.cursor =+ seam.orientation === "vertical" ? "col-resize" : "row-resize";+ document.body.style.userSelect = "none";++ const detach = () => {+ if (frame !== undefined) cancelAnimationFrame(frame);+ frame = undefined;+ window.removeEventListener("pointermove", onMove);+ window.removeEventListener("pointerup", settle);+ window.removeEventListener("pointercancel", settle);+ document.body.style.cursor = previousCursor;+ document.body.style.userSelect = previousSelect;+ stopDrag.current = null;+ };+ // A release commits; so does a cancelled pointer (a touch taken over by+ // the browser, a window that lost the device), because the boxes are+ // already painted at the dragged sizes.+ function settle() {+ // Land the last move before committing, so the sizes React is told+ // about are the ones already on screen.+ if (frame !== undefined) {+ cancelAnimationFrame(frame);+ apply();+ }+ detach();+ const settled = live.current;+ active.current = null;+ live.current = null;+ setDragging(null);+ if (settled) commit(settled);}- const settled = live.current;- active.current = null;- live.current = null;- setDragging(null);- if (settled) commit(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.- 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;- const previousSelect = document.body.style.userSelect;- document.body.style.cursor =- active.current?.seam.orientation === "vertical" ? "col-resize" : "row-resize";- document.body.style.userSelect = "none";+ window.addEventListener("pointermove", onMove);+ window.addEventListener("pointerup", settle);+ window.addEventListener("pointercancel", settle);+ stopDrag.current = detach;+ },+ [commit],+ );- 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;- };- }, [commit, dragging]);+ // A grid unmounted mid-drag must not leave listeners or a locked cursor.+ useEffect(() => () => stopDrag.current?.(), []);const nudge = useCallback((seam: PaneSeam, deltaPx: number) => {