Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(desktop): keep roster drags and resize cursors reliable

leepokaib2c923346f64
diff --git a/apps/desktop/src/renderer/components/Controls.tsx b/apps/desktop/src/renderer/components/Controls.tsx
index aebb36b7..ae149904 100644
--- a/apps/desktop/src/renderer/components/Controls.tsx
+++ b/apps/desktop/src/renderer/components/Controls.tsx
@@ -1,4 +1,4 @@
-import { Children, Fragment, useRef, useState, type CSSProperties, type KeyboardEvent, type PointerEvent, type ReactNode } from 'react'
+import { Children, Fragment, useEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type PointerEvent, type ReactNode } from 'react'
import { Icon } from './Icon'
import { AnchoredMenu, IconButtonBase, type MenuItem } from './Overlay'
import { HStack, Spacer, VStack } from './Stack'
@@ -262,6 +262,9 @@ export function ResizeHandle({ label, width, min, max, edge, onResize, onDraggin
onDragging?: (dragging: boolean) => void
}) {
const start = useRef<{ x: number; width: number } | null>(null)
+ useEffect(() => () => {
+ if (start.current) document.documentElement.classList.remove('col-resizing')
+ }, [])
// Dragging toward the panel's outside grows it.
const grow = edge === 'trailing' ? 1 : -1
const end = () => {
diff --git a/apps/desktop/src/renderer/lib/pointer-drag.test.ts b/apps/desktop/src/renderer/lib/pointer-drag.test.ts
index 2b475c79..effa163c 100644
--- a/apps/desktop/src/renderer/lib/pointer-drag.test.ts
+++ b/apps/desktop/src/renderer/lib/pointer-drag.test.ts
@@ -14,7 +14,10 @@ Object.assign(globalThis, {
})
const { pointerDrag } = await import('./pointer-drag.ts')
-const fire = (type: string, props: Record<string, unknown> = {}) => target.dispatchEvent(Object.assign(new Event(type), props))
+const fire = (type: string, props: Record<string, unknown> = {}) => target.dispatchEvent(Object.assign(new Event(type, { cancelable: true }), props))
+/** Whether a click now reaches the page (`false`: the drag swallowed it). */
+const clickGetsThrough = () => fire('click')
+const nextTask = () => new Promise((resolve) => setTimeout(resolve, 0))
const press = (handlers: PointerDragHandlers) =>
pointerDrag(handlers).onPointerDown({ button: 0, clientX: 0, clientY: 0, metaKey: false, ctrlKey: false, shiftKey: false } as never)
@@ -68,3 +71,31 @@ test('Escape or a cancelled pointer ends the drag without a drop', () => {
assert.deepEqual(cancelled.calls, ['start 0,0', 'over 0,10', 'cancel'])
assert.equal(classes.has('pointer-dragging'), false)
})
+
+test('the click that ends a drag is swallowed, later clicks are not', async () => {
+ const { handlers } = recorder()
+ press(handlers)
+ fire('pointermove', { clientX: 0, clientY: 10 })
+ fire('pointerup')
+ assert.equal(clickGetsThrough(), false)
+ await nextTask()
+ assert.equal(clickGetsThrough(), true)
+})
+
+test('after Escape, the release that ends the gesture does not click', async () => {
+ const { handlers } = recorder()
+ press(handlers)
+ fire('pointermove', { clientX: 0, clientY: 10 })
+ fire('keydown', { key: 'Escape' })
+ fire('pointerup')
+ assert.equal(clickGetsThrough(), false)
+ await nextTask()
+ assert.equal(clickGetsThrough(), true)
+})
+
+test('a plain click is never swallowed', () => {
+ const { handlers } = recorder()
+ press(handlers)
+ fire('pointerup')
+ assert.equal(clickGetsThrough(), true)
+})
diff --git a/apps/desktop/src/renderer/lib/pointer-drag.ts b/apps/desktop/src/renderer/lib/pointer-drag.ts
index e8a4cd77..38ed93f2 100644
--- a/apps/desktop/src/renderer/lib/pointer-drag.ts
+++ b/apps/desktop/src/renderer/lib/pointer-drag.ts
@@ -63,6 +63,9 @@ export function pointerDrag(handlers: PointerDragHandlers) {
e.preventDefault()
e.stopPropagation()
cancel()
+ // The release still to come is the end of this gesture (unless a new press comes first).
+ window.addEventListener('pointerup', swallowNextClick, { once: true })
+ window.addEventListener('pointerdown', () => window.removeEventListener('pointerup', swallowNextClick), { once: true })
}
window.addEventListener('pointermove', move)
window.addEventListener('pointerup', up)
diff --git a/apps/desktop/src/renderer/styles/theme.css b/apps/desktop/src/renderer/styles/theme.css
index 67bd3cf9..61e8955f 100644
--- a/apps/desktop/src/renderer/styles/theme.css
+++ b/apps/desktop/src/renderer/styles/theme.css
@@ -177,16 +177,18 @@ button {
text-align: inherit;
}
/* Anything clickable shows the pointing hand; :where keeps it below each view's own cursor. */
-:where(button:not(:disabled), a[href], [role='button'], [role='tab'], [role='switch'], [role='menuitem'], [role='menuitemradio'], [role='option'], select, summary, label:has(input)) {
+:where(button:not(:disabled), a[href], [role='button'], [role='tab'], [role='switch'], [role='menuitem'], [role='menuitemradio'], [role='option'], select, summary) {
cursor: pointer;
}
/* A drag in progress (lib/pointer-drag.ts, ResizeHandle) keeps its cursor wherever the pointer goes. */
.pointer-dragging,
-.pointer-dragging * {
+.pointer-dragging *,
+.pointer-dragging *::after {
cursor: grabbing !important;
}
.col-resizing,
-.col-resizing * {
+.col-resizing *,
+.col-resizing *::after {
cursor: col-resize !important;
}
button:focus-visible,
diff --git a/apps/desktop/src/renderer/views/BotRoster.tsx b/apps/desktop/src/renderer/views/BotRoster.tsx
index fa7b839e..43fb1495 100644
--- a/apps/desktop/src/renderer/views/BotRoster.tsx
+++ b/apps/desktop/src/renderer/views/BotRoster.tsx
@@ -25,6 +25,7 @@ interface Lift {
width: number
grab: Point
at: Point
+ seq: number
}
export function BotRoster({ roster, compact, onContext }: {
@@ -46,6 +47,10 @@ export function BotRoster({ roster, compact, onContext }: {
const [lift, setLift] = useState<Lift | null>(null)
const ghost = useRef<HTMLDivElement>(null)
const grab = useRef<Point>({ x: 0, y: 0 })
+ const settle = useRef<ReturnType<typeof setTimeout> | null>(null)
+ // Near the roster's top or bottom edge a drag scrolls it, from the last point the pointer was at.
+ const pointer = useRef<Point>({ x: 0, y: 0 })
+ const edgeScroll = useRef(0)
const itemsByKey = useRef(new Map<string, RosterItem>())
itemsByKey.current = new Map(roster.sections.flatMap((s) => s.items).map((item) => [refKey(item.ref), item]))
@@ -58,16 +63,38 @@ export function BotRoster({ roster, compact, onContext }: {
// The row lifts: a copy follows the pointer from where it was grabbed; the row's slot stays open.
const liftRow = (item: RosterItem, siblings: RosterItem[], from: Point) => {
+ // A lift during the last one's settle takes over from it.
+ if (settle.current) clearTimeout(settle.current)
+ settle.current = null
const rect = rowRect(item)
setBotDrag({ item, ids: siblings.map((s) => s.bot.id) })
if (!rect) return
grab.current = { x: from.x - rect.left, y: from.y - rect.top }
- setLift({ item, width: rect.width, grab: grab.current, at: from })
+ setLift((last) => ({ item, width: rect.width, grab: grab.current, at: from, seq: (last?.seq ?? 0) + 1 }))
}
- // Any row of the same computer is a target; only rows with the same pin state make room.
const dragOver = (at: Point, under: Element | null) => {
+ pointer.current = at
if (ghost.current) ghost.current.style.translate = ghostTranslate(at, grab.current)
+ makeRoom(under)
+ if (!edgeScroll.current) scrollAtEdge()
+ }
+
+ const scrollAtEdge = () => {
+ const current = drag.current
+ const scroller = current && rowElement(current.item)?.closest<HTMLElement>('.roster')
+ if (!scroller) return void (edgeScroll.current = 0)
+ const box = scroller.getBoundingClientRect()
+ const { x, y } = pointer.current
+ const reach = Math.max(0, box.top + EDGE - y) - Math.max(0, y - (box.bottom - EDGE))
+ if (!reach) return void (edgeScroll.current = 0)
+ scroller.scrollTop -= Math.round((reach / EDGE) * EDGE_SPEED)
+ makeRoom(document.elementFromPoint(x, y))
+ edgeScroll.current = requestAnimationFrame(scrollAtEdge)
+ }
+
+ // Any row of the same computer is a target; only rows with the same pin state make room.
+ const makeRoom = (under: Element | null) => {
const current = drag.current
const row = under?.closest<HTMLElement>('[data-roster-row]')
const item = row && itemsByKey.current.get(row.dataset.rosterRow!)
@@ -78,20 +105,29 @@ export function BotRoster({ roster, compact, onContext }: {
}
const endDrag = () => {
+ cancelAnimationFrame(edgeScroll.current)
+ edgeScroll.current = 0
+ settle.current = null
setBotDrag(null)
setLift(null)
}
- // The copy settles into the row's new slot, then the row shows again.
+ // The copy settles into the row's new slot (when it's in view), then the row shows again.
const drop = () => {
const current = drag.current
if (!current) return endDrag()
+ cancelAnimationFrame(edgeScroll.current)
if (current.ids.some((id, index) => id !== current.item.store.roster[index]?.id)) current.item.store.reorder(current.ids)
- const slot = rowRect(current.item)
- if (!slot || !ghost.current || reduceMotion()) return endDrag()
+ const row = rowElement(current.item)
+ // Measured where the row ends up, not partway through its slide.
+ for (const animation of row?.getAnimations() ?? []) animation.finish()
+ const slot = row?.getBoundingClientRect()
+ const view = row?.closest('.roster')?.getBoundingClientRect()
+ const visible = slot && view && slot.bottom > view.top && slot.top < view.bottom
+ if (!slot || !visible || !ghost.current || reduceMotion()) return endDrag()
ghost.current.classList.add('settling')
ghost.current.style.translate = `${slot.left}px ${slot.top}px`
- setTimeout(endDrag, SETTLE_MS)
+ settle.current = setTimeout(endDrag, SETTLE_MS)
}
const row = (item: RosterItem, siblings: RosterItem[]) => {
@@ -109,10 +145,7 @@ export function BotRoster({ roster, compact, onContext }: {
title={many ? `${item.bot.name} · ${item.store.hostName}` : item.bot.name}
selected={isSelected}
dragKey={key}
- onHover={(on) => {
- if (drag.current) return
- setHovered((h) => (on ? key : h === key ? null : h))
- }}
+ onHover={(on) => setHovered((h) => (on ? key : h === key ? null : h))}
onClick={() => app.select(item.ref)}
onContext={(x, y) => onContext(item.bot, item.store, x, y)}
lifted={held && lift !== null}
@@ -140,7 +173,7 @@ export function BotRoster({ roster, compact, onContext }: {
return (
<>
{sections}
- {lift ? <RosterGhost lift={lift} ghost={ghost} compact={compact} /> : null}
+ {lift ? <RosterGhost key={lift.seq} lift={lift} ghost={ghost} compact={compact} /> : null}
</>
)
}
@@ -206,9 +239,17 @@ const noMembers: Bot[] = []
/** How long the lifted copy takes to settle into its slot (`--morph`). */
const SETTLE_MS = 200
+/** How close to the roster's edge a drag starts scrolling it, and how fast (points per frame). */
+const EDGE = 36
+const EDGE_SPEED = 12
+
+function rowElement(item: RosterItem): HTMLElement | null {
+ return document.querySelector<HTMLElement>(`[data-roster-row="${CSS.escape(refKey(item.ref))}"]`)
+}
+
/** Where a row is on screen now. */
function rowRect(item: RosterItem): DOMRect | undefined {
- return document.querySelector(`[data-roster-row="${CSS.escape(refKey(item.ref))}"]`)?.getBoundingClientRect()
+ return rowElement(item)?.getBoundingClientRect()
}
/** The lifted copy's `translate` that keeps the point it was grabbed by under the pointer. */
diff --git a/apps/desktop/src/renderer/views/chat-window.css b/apps/desktop/src/renderer/views/chat-window.css
index a883a97d..ab416bb3 100644
--- a/apps/desktop/src/renderer/views/chat-window.css
+++ b/apps/desktop/src/renderer/views/chat-window.css
@@ -129,6 +129,10 @@ html[data-platform="darwin"] .sidebar-header {
.roster-row.selected {
background: var(--roster-selected);
}
+/* Rows the pointer passes over while dragging don't light up. */
+.pointer-dragging .roster-row.hovered:not(.selected) {
+ background: none;
+}
/* Dragging (iOS's lifted cell): the row's slot stays open while a smaller, translucent copy
follows the pointer, then settles into the slot. */
.roster-row.lifted {
diff --git a/apps/desktop/src/renderer/views/thread/ChatSidePanel.tsx b/apps/desktop/src/renderer/views/thread/ChatSidePanel.tsx
index 348d0beb..993a1dd6 100644
--- a/apps/desktop/src/renderer/views/thread/ChatSidePanel.tsx
+++ b/apps/desktop/src/renderer/views/thread/ChatSidePanel.tsx
@@ -1,4 +1,4 @@
-import { useRef, useState, type ReactNode } from 'react'
+import { useRef, type ReactNode } from 'react'
import { ResizeHandle } from '../../components/Controls'
import { usePresence } from '../../components/Overlay'
@@ -19,7 +19,6 @@ export function ChatSidePanel({ open, width, min, max, onResize, children }: {
// Animate explicit open/close actions without animating the initial mount.
const { mounted, shown } = usePresence(open, 300, false)
const last = useRef({ width, children })
- const [resizing, setResizing] = useState(false)
if (open) last.current = { width, children }
const content = open ? { width, children } : last.current
// The content plus the edge's hairline.
@@ -28,8 +27,8 @@ export function ChatSidePanel({ open, width, min, max, onResize, children }: {
<>
<div className="side-panel-slot" style={{ width: open ? panelWidth : 0 }} />
{mounted ? (
- <div className={`side-panel ${resizing ? 'resizing' : ''}`} inert={!open} style={{ width: panelWidth, right: shown ? 0 : -panelWidth }}>
- <ResizeHandle label="Resize panel" width={content.width} min={min} max={max} edge="leading" onResize={onResize} onDragging={setResizing} />
+ <div className="side-panel" inert={!open} style={{ width: panelWidth, right: shown ? 0 : -panelWidth }}>
+ <ResizeHandle label="Resize panel" width={content.width} min={min} max={max} edge="leading" onResize={onResize} />
<div className="side-panel-content" style={{ width: content.width }}>{content.children}</div>
</div>
) : null}
diff --git a/apps/desktop/src/renderer/views/thread/thread.css b/apps/desktop/src/renderer/views/thread/thread.css
index ec448715..aaeb9b2e 100644
--- a/apps/desktop/src/renderer/views/thread/thread.css
+++ b/apps/desktop/src/renderer/views/thread/thread.css
@@ -406,7 +406,6 @@
overflow: clip;
overflow-clip-margin: 4px;
}
-.side-panel.resizing { transition: none; }
.side-panel-content {
height: 100%;
flex: none;