diff --git a/src/components/sidebar/view/subcomponents/SidebarSessionItem.tsx b/src/components/sidebar/view/subcomponents/SidebarSessionItem.tsx index cb22a7a2..209a9832 100644 --- a/src/components/sidebar/view/subcomponents/SidebarSessionItem.tsx +++ b/src/components/sidebar/view/subcomponents/SidebarSessionItem.tsx @@ -1,3 +1,4 @@ +import { useEffect, useRef } from 'react'; import { Check, Edit2, Trash2, X } from 'lucide-react'; import type { TFunction } from 'i18next'; @@ -76,7 +77,28 @@ export default function SidebarSessionItem({ }: SidebarSessionItemProps) { const sessionView = createSessionViewModel(session, currentTime, t); const isSelected = selectedSession?.id === session.id; + const isEditing = editingSession === session.id; const compactSessionAge = formatCompactSessionAge(sessionView.sessionTime, currentTime); + const editingContainerRef = useRef(null); + + // The rename panel sits inside a group-hover opacity wrapper, so leaving the row + // would visually hide it. While editing, dismiss only when the user clicks outside + // the panel (matches Escape / cancel-button behaviour). + useEffect(() => { + if (!isEditing) { + return; + } + + const handlePointerDown = (event: MouseEvent) => { + const container = editingContainerRef.current; + if (container && !container.contains(event.target as Node)) { + onCancelEditingSession(); + } + }; + + document.addEventListener('mousedown', handlePointerDown); + return () => document.removeEventListener('mousedown', handlePointerDown); + }, [isEditing, onCancelEditingSession]); // Sessions are owned by a project identified by `projectId` (DB primary key) // after the projectName → projectId migration. @@ -174,7 +196,12 @@ export default function SidebarSessionItem({
{sessionView.sessionName}
{compactSessionAge && ( - + {compactSessionAge} )} @@ -186,8 +213,14 @@ export default function SidebarSessionItem({
-
- {editingSession === session.id ? ( +
+ {isEditing ? ( <>