Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(ui): context menu flips away from the viewport edges
enes003d2065eb93
diff --git a/src/renderer/components/ContextMenu.tsx b/src/renderer/components/ContextMenu.tsxindex 4e0d6ed66..bfd8bd55c 100644--- a/src/renderer/components/ContextMenu.tsx+++ b/src/renderer/components/ContextMenu.tsx@@ -1,4 +1,4 @@-import { useState, type ReactNode } from 'react'+import { useLayoutEffect, useRef, useState, type ReactNode } from 'react'import { createPortal } from 'react-dom'import { NODE_COLORS } from '../state/workspace'@@ -48,7 +48,27 @@ interface ContextMenuProps {export function ContextMenu({ x, y, items, onClose, zIndex, scroll }: ContextMenuProps) {// Keep the menu one above its backdrop (matches the default 46/45 CSS ordering).const backdropStyle = zIndex != null ? { zIndex } : undefined- const menuStyle = zIndex != null ? { top: y, left: x, zIndex: zIndex + 1 } : { top: y, left: x }+ // Flip away from the viewport edges: a right-click near the bottom (or right) edge used to+ // open the menu DOWNWARD off-screen, cutting the tail rows off. Measured after render but+ // BEFORE paint (useLayoutEffect — no visible jump): if the menu would overflow below, it+ // opens upward from the cursor (native-menu behavior); same flip horizontally. The margin+ // clamp is the last resort for a menu taller than the viewport itself.+ const menuRef = useRef<HTMLDivElement>(null)+ const [pos, setPos] = useState({ top: y, left: x })+ useLayoutEffect(() => {+ const el = menuRef.current+ if (!el) return+ const M = 6+ const w = el.offsetWidth+ const h = el.offsetHeight+ const top = y + h > window.innerHeight - M ? Math.max(M, y - h) : y+ const left = x + w > window.innerWidth - M ? Math.max(M, x - w) : x+ // Identity-guarded: `items` often gets a fresh array identity per parent render, and an+ // unconditional setPos would re-render forever.+ setPos((p) => (p.top === top && p.left === left ? p : { top, left }))+ }, [x, y, items])+ const menuStyle =+ zIndex != null ? { top: pos.top, left: pos.left, zIndex: zIndex + 1 } : { top: pos.top, left: pos.left }// Index of the row whose submenu flyout is currently open (hover-driven).const [openSub, setOpenSub] = useState<number | null>(null)return createPortal(@@ -60,6 +80,7 @@ export function ContextMenu({ x, y, items, onClose, zIndex, scroll }: ContextMenonClick={onClose}/><div+ ref={menuRef}className={`ctx-menu${scroll ? ' ctx-menu--scroll' : ''}`}style={menuStyle}onClick={(e) => e.stopPropagation()}