graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Split chats by dragging sidebar rows onto each other
Rach6036d50ccd89
diff --git a/apps/native/components/site/useTabDrag.tsx b/apps/native/components/site/useTabDrag.tsxindex 7f9ee772..6bfc8677 100644--- a/apps/native/components/site/useTabDrag.tsx+++ b/apps/native/components/site/useTabDrag.tsx@@ -1,6 +1,6 @@"use client";import { useEffect, useLayoutEffect, useRef, useState, type PointerEvent as ReactPointerEvent, type MouseEvent } from "react";-import type { TabDrop } from "@/lib/tab-drop";+import { sidebarRowDrop, type TabDrop } from "@/lib/tab-drop";import { captureTabLayout, settleTabLayout } from "./tab-drag-motion";import styles from "./tab-drag.module.css";type Preview = { drop: TabDrop; left: number; top: number; width: number; height: number; label: string };@@ -47,7 +47,15 @@ export function useTabDrag(onDrop: (id: number, drop: TabDrop) => void) {const r = tab.getBoundingClientRect();const vertical = tab.closest('[data-session-navigation="sidebar"]') !== null;const after = vertical ? y > r.top + r.height / 2 : x > r.left + r.width / 2;- if (vertical) return { drop: { kind: "tab", id: Number(tab.dataset.tabId), after }, left: r.left, top: after ? r.bottom - 2 : r.top, width: r.width, height: 3, label: "Move chat" };+ if (vertical) {+ const drop = sidebarRowDrop(id, Number(tab.dataset.tabId), x, y, r);+ if (!drop) return null;+ if (drop.kind === "split") return {+ drop, left: drop.edge === "right" ? r.left + r.width / 2 : r.left, top: r.top,+ width: r.width / 2, height: r.height, label: drop.edge === "left" ? "Split left" : "Split right",+ };+ return { drop, left: r.left, top: drop.after ? r.bottom - 2 : r.top, width: r.width, height: 3, label: "Move chat" };+ }return { drop: { kind: "tab", id: Number(tab.dataset.tabId), after }, left: after ? r.right - 2 : r.left, top: r.top, width: 3, height: r.height, label: "Move tab" };}const pane = element?.closest<HTMLElement>('[data-chat]');diff --git a/apps/native/lib/tab-drop.test.ts b/apps/native/lib/tab-drop.test.tsindex 65ff6c37..c20c8aa6 100644--- a/apps/native/lib/tab-drop.test.ts+++ b/apps/native/lib/tab-drop.test.ts@@ -1,5 +1,5 @@import {test, expect} from 'bun:test';-import {reorderTabs, splitTab} from './tab-drop';+import {reorderTabs, sidebarRowDrop, splitTab} from './tab-drop';test('reordering tabs preserves the conversation objects and active pane order', () => {const tabs = [{id:1, draft:'first'}, {id:2, draft:'second'}, {id:3, draft:'third'}];const next = reorderTabs(tabs, 1, 3, true);@@ -15,3 +15,11 @@ test('splitting moves an existing chat without duplicates and respects the cap',expect(splitTab([1,2,3,4],4,1,'right')).toEqual([1,4,2,3]);expect(splitTab([1],1,1,'right')).toBeNull();});+test('sidebar rows split on the outer thirds and reorder in the middle', () => {+ const rect = { left: 0, top: 0, width: 100, height: 32 };+ expect(sidebarRowDrop(1, 2, 10, 8, rect)).toEqual({ kind: "split", id: 2, edge: "left" });+ expect(sidebarRowDrop(1, 2, 90, 8, rect)).toEqual({ kind: "split", id: 2, edge: "right" });+ expect(sidebarRowDrop(1, 2, 50, 8, rect)).toEqual({ kind: "tab", id: 2, after: false });+ expect(sidebarRowDrop(1, 2, 50, 24, rect)).toEqual({ kind: "tab", id: 2, after: true });+ expect(sidebarRowDrop(2, 2, 10, 8, rect)).toBeNull();+});diff --git a/apps/native/lib/tab-drop.ts b/apps/native/lib/tab-drop.tsindex f35561b8..9320bf51 100644--- a/apps/native/lib/tab-drop.ts+++ b/apps/native/lib/tab-drop.ts@@ -1,4 +1,19 @@export type TabDrop = { kind: "tab"; id: number; after: boolean } | { kind: "split"; id: number; edge: "left" | "right" | "top" | "bottom" };++/** Sidebar rows: outer thirds split beside the target, the middle reorders. */+export function sidebarRowDrop(+ sourceId: number,+ targetId: number,+ x: number,+ y: number,+ rect: { left: number; top: number; width: number; height: number },+): TabDrop | null {+ if (sourceId === targetId || rect.width <= 0) return null;+ const relX = (x - rect.left) / rect.width;+ if (relX < 0.28) return { kind: "split", id: targetId, edge: "left" };+ if (relX > 0.72) return { kind: "split", id: targetId, edge: "right" };+ return { kind: "tab", id: targetId, after: y > rect.top + rect.height / 2 };+}export function reorderTabs<T extends { id: number }>(tabs: T[], source: number, target: number, after: boolean): T[] {const item = tabs.find(tab => tab.id === source);if (!item || source === target || !tabs.some(tab => tab.id === target)) return tabs;