/** * SessionContextMenu - Right-click context menu for sidebar session items. * Supports opening in current pane, new tab, and split right. * Shows keyboard shortcut hints for actions that have them. */ import { useEffect, useRef } from 'react'; import { MAX_PANES } from '@renderer/types/panes'; import { Eye, EyeOff, Pin, PinOff } from 'lucide-react'; interface SessionContextMenuProps { x: number; y: number; sessionId: string; projectId: string; sessionLabel: string; paneCount: number; isPinned: boolean; isHidden: boolean; onClose: () => void; onOpenInCurrentPane: () => void; onOpenInNewTab: () => void; onSplitRightAndOpen: () => void; onTogglePin: () => void; onToggleHide: () => void; } export const SessionContextMenu = ({ x, y, paneCount, isPinned, isHidden, onClose, onOpenInCurrentPane, onOpenInNewTab, onSplitRightAndOpen, onTogglePin, onToggleHide, }: SessionContextMenuProps): React.JSX.Element => { const menuRef = useRef(null); useEffect(() => { const handleMouseDown = (e: MouseEvent): void => { if (menuRef.current && !menuRef.current.contains(e.target as Node)) { onClose(); } }; const handleKeyDown = (e: KeyboardEvent): void => { if (e.key === 'Escape') onClose(); }; document.addEventListener('mousedown', handleMouseDown); document.addEventListener('keydown', handleKeyDown); return () => { document.removeEventListener('mousedown', handleMouseDown); document.removeEventListener('keydown', handleKeyDown); }; }, [onClose]); const menuWidth = 240; const menuHeight = 204; const clampedX = Math.min(x, window.innerWidth - menuWidth - 8); const clampedY = Math.min(y, window.innerHeight - menuHeight - 8); const handleClick = (action: () => void) => () => { action(); onClose(); }; const atMaxPanes = paneCount >= MAX_PANES; return (
: } onClick={handleClick(onTogglePin)} /> : } onClick={handleClick(onToggleHide)} />
); }; const MenuItem = ({ label, shortcut, icon, onClick, disabled, }: { label: string; shortcut?: string; icon?: React.ReactNode; onClick: () => void; disabled?: boolean; }): React.JSX.Element => { return ( ); };