Files
Netcatty/components/terminalLayer/TerminalFocusSidebar.tsx
陈大猫 f5c3302329 feat: terminal rename, closeSession shortcut, and pane zoom (#1459)
* feat: auto-poll Docker capabilities while Docker tab is active

When the Docker tab is visible and hasDocker is not yet true,
poll refreshCapabilities() at the process refresh interval.
Stop polling once hasDocker becomes true, or when switching
to a different tab.

* fix: use resolvedTab instead of activeTab for Docker auto-poll condition

The auto-poll useEffect condition used activeTab, which stays stale
when Docker becomes unavailable. Changed to resolvedTab which reflects
the actual displayed tab. Also updated the dep array.

* fix: replace setInterval with setTimeout recursion in Docker tab probe

Replace setInterval-based polling with setTimeout recursion in the Docker
tab capability probe effect. This ensures the next probe only starts after
the previous one finishes, avoiding overlapping probes when SSH timeout
exceeds the polling interval.

- Add dockerPollTimerRef to track the timeout handle
- Use async pollOnce() that awaits refreshCapabilities() before scheduling next
- Use cancelled flag in cleanup to prevent scheduling after unmount
- Keep same dependency array for correctness

* fix: stabilize docker poll timer by using useRef for refreshCapabilities

refreshCapabilities() can return a new reference on every render, causing
the useEffect to re-run on every render — cleanup cancels the polling timer,
then the effect immediately calls pollOnce(), effectively bypassing the
configured timeout interval.

Fix: store refreshCapabilities in a useRef (refreshRef), use
refreshRef.current() inside pollOnce(), and replace refreshCapabilities
with refreshRef in the useEffect dependency array.

Closes #PR1456 Codex P2 review item.

* fix: delay auto-poll first probe by one interval to avoid overlap with tab-switch probe

When switching to the Docker tab, two mechanisms were triggering probes:
1. tab-switch effect (line 67-76): immediate probe via refreshCapabilities()
2. auto-poll effect: pollOnce() executing immediately on mount

This caused duplicate probes that waste SSH channel resources.

Fix: pollOnce() no longer fires on mount. Instead, the effect schedules the
first probe with setTimeout(pollOnce, capabilitiesTtlMs), so the first probe
happens after one full interval. Subsequent probes continue at interval pace
via the setTimeout recursion in pollOnce itself.

The tab-switch effect still fires the immediate probe (the correct one),
so responsiveness on tab switch is preserved.

* fix: reset cancelledRef in effect body to prevent permanent stalling of Docker polling

The cancelledRef was set to true in the cleanup function when dependencies
changed, but never reset when the effect re-ran. This caused pollOnce to
always early-return on subsequent timer ticks, permanently halting
Docker capability probing after the first dependency change.

* fix(system-manager): replace cancelledRef with closure variables for per-effect cancellation

Each effect generation now has its own  and  closure
variables instead of shared  / . This
prevents stale probes from surviving cleanup when the panel hides and
re-shows (Codex P2 review).

* fix: wrap refreshCapabilities in try/catch to keep polling on exception

If refreshCapabilities throws (instead of returning {success: false}),
the await would exit pollOnce without scheduling the next setTimeout,
silently killing Docker auto-detection polling.

* fix: add in-flight probe guard to prevent tab-switch and auto-poll concurrent probes

Add probingRef to track whether a capabilities probe is already in-flight.
- Tab-switch effect for Docker branch checks probingRef before starting a new probe
- Auto-poll pollOnce checks probingRef at entry and sets/clears it around the actual probe
- Tmux branch left unchanged as it has no auto-poll overlap risk

* fix: re-schedule next poll timer when probe is in-flight

When probingRef.current is true (tab-switch probe still running),
pollOnce was returning early without scheduling the next timer,
causing auto-poll to stop permanently afterward.

Now it schedules the next poll within the interval and returns,
so the polling loop keeps running until a slot where no probe is
active.

* fix: convert comments to ASCII-only English

- Line 105: translate Chinese comment to 'probe is in-flight, reschedule for next cycle'
- Line 113: replace em dash (U+2014) with ASCII dash

* feat: session inline rename, closeSession shortcut, pane zoom

* fix: sidebar inline rename with local state

* fix: add sessionDisplayName to terminalPropsAreEqual comparator

The Terminal component is wrapped with React.memo(…, terminalPropsAreEqual),
but the comparator was missing a check for sessionDisplayName. After renaming
a session, the pane title bar would show the old name until some other prop
changed and triggered a re-render.

Add prev.sessionDisplayName === next.sessionDisplayName to the comparator
so that display name changes cause the Terminal to re-render immediately.

* fix: add onStartSessionRename to TerminalLayerWorkspaceSection ctx destructuring and TerminalPanesHost props

* fix: add toggleWorkspaceViewMode to executeHotkeyActionImpl destructuring

The togglePaneZoom handler calls toggleWorkspaceViewMode() but it
wasn't destructured from getCtx(), causing a ReferenceError at runtime.

* fix: restore truncated ctx object in TerminalView render call

The TerminalView ctx object literal on line 1265 was truncated to
'showSele...' due to an editing tool truncation bug, causing
Parsing error: ',' expected on npm run lint / tsc --noEmit.

Restored the missing fields from the base commit:
showSelectionAIAction, snippets, status, statusDotTone, sudoHintRef,
sudoHintText: t("terminal.sudoHint.pressEnter"), t, termRef,
terminalBackend, terminalContextActions, terminalCwdTracker,
terminalPreviewVars, terminalSettings, timeLeft, toast, zmodem

Kept the PR's new additions (isVisible, onRename, sessionDisplayName)
intact.

* fix: add toggleWorkspaceViewMode to executeHotkeyAction context and add terminal.menu.rename translations

- Add toggleWorkspaceViewMode to the context getter in executeHotkeyAction (App.tsx)
- Add terminal.menu.rename translation for en (Rename), zh-CN (重命名), ru (Переименовать)

* fix: validate focusedSessionId before closing in closeSession hotkey

When closeSession hotkey fires, workspace.focusedSessionId may reference
a session that was already closed by another trigger (e.g., mouse click
on tab close button). Collect alive session IDs from the workspace root
and fall back to the first living pane if the stored focusedSessionId
is stale.

* fix(auto-poll): check useSessionCapabilities probing state in pollOnce

When auto-poll timer fires before the initial probe (from
useSessionCapabilities) completes, probingRef.current is still false
because the initial probe doesn't set it — causing a second overlapping
probe.

Add  check so that any in-flight probe from any path
(initial/auto-poll/tab-switch) prevents auto-poll overlap.

PR #1459

* fix: address remaining Codex review issues

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat: add detach session from workspace with toolbar button and context menu

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: use customName in pane header display name for renamed sessions

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: refine workspace terminal detach interactions

* fix: preserve workspace detach tab ordering

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 01:30:44 +08:00

586 lines
23 KiB
TypeScript

import { Circle, Columns2, Plus, Search, Server } from 'lucide-react';
import React, { memo, useCallback, useMemo, useState, type DragEvent, type MouseEvent } from 'react';
import { useStoredNumber } from '../../application/state/useStoredNumber';
import { resolveWorkspaceFocusSessionOrder } from '../../domain/workspace';
import { STORAGE_KEY_WORKSPACE_FOCUS_SIDEBAR_WIDTH } from '../../infrastructure/config/storageKeys';
import { cn } from '../../lib/utils';
import type { Host, TerminalSession, TerminalTheme, Workspace } from '../../types';
import { DistroAvatar } from '../DistroAvatar';
import { SessionInlineRenameInput } from '../terminal/SessionInlineRenameInput';
import { SessionTabContextMenuContent } from '../top-tabs/SessionTabContextMenuContent';
import { Button } from '../ui/button';
import { ContextMenu, ContextMenuTrigger } from '../ui/context-menu';
import { Input } from '../ui/input';
import { ScrollArea } from '../ui/scroll-area';
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
interface TerminalFocusSidebarProps {
activeWorkspace: Workspace;
focusedSessionId: string | undefined;
onReorderWorkspaceSessions?: (workspaceId: string, draggedSessionId: string, targetSessionId: string, position: 'before' | 'after') => void;
onRequestAddToWorkspace?: (workspaceId: string) => void;
onCloseSession: (sessionId: string) => void;
onCopySession?: (sessionId: string) => void;
onCopySessionToNewWindow?: (sessionId: string) => void;
onDetachSessionFromWorkspace?: (sessionId: string) => void;
onSetWorkspaceFocusedSession?: (workspaceId: string, sessionId: string) => void;
onToggleWorkspaceViewMode?: (workspaceId: string) => void;
onSubmitSessionRename: (sessionId: string, name: string) => void;
resolvedPreviewTheme: TerminalTheme;
sessionHostsMap: Map<string, Host>;
sessions: TerminalSession[];
t: (key: string) => string;
}
type FocusSidebarTheme = {
termBg: string;
termFg: string;
selectedBg: string;
selectedHoverBg: string;
unselectedHoverBg: string;
unselectedFg: string;
mutedFg: string;
separator: string;
};
type WorkspaceFocusSessionRowProps = {
session: TerminalSession;
host: Host | undefined;
isSelected: boolean;
isRenaming: boolean;
renameValue: string;
onStartRename: (sessionId: string) => void;
onSubmitRename: (name: string) => void;
onCancelRename: () => void;
onCloseSession: (sessionId: string) => void;
onCopySession?: (sessionId: string) => void;
onCopySessionToNewWindow?: (sessionId: string) => void;
onDetachSessionFromWorkspace?: (sessionId: string) => void;
isDragging: boolean;
dropPosition: 'before' | 'after' | null;
theme: FocusSidebarTheme;
onSelect: (sessionId: string) => void;
onDragStart: (event: DragEvent, sessionId: string) => void;
onDragOver: (event: DragEvent, sessionId: string) => void;
onDrop: (event: DragEvent, sessionId: string) => void;
onDragEnd: () => void;
t: (key: string) => string;
};
const WorkspaceFocusSessionRow = memo<WorkspaceFocusSessionRowProps>(({
session,
host,
isSelected,
isRenaming,
renameValue,
onStartRename,
onSubmitRename,
onCancelRename,
onCloseSession,
onCopySession,
onCopySessionToNewWindow,
onDetachSessionFromWorkspace,
isDragging,
dropPosition,
theme,
onSelect,
onDragStart,
onDragOver,
onDrop,
onDragEnd,
t,
}) => {
const {
termFg,
selectedBg,
selectedHoverBg,
unselectedHoverBg,
unselectedFg,
mutedFg,
} = theme;
const statusColor = session.status === 'connected'
? 'text-emerald-500'
: session.status === 'connecting'
? 'text-amber-500'
: 'text-red-500';
const restBg = isSelected ? selectedBg : 'transparent';
const hoverBg = isSelected ? selectedHoverBg : unselectedHoverBg;
const rowFg = isSelected ? termFg : unselectedFg;
return (
<ContextMenu>
<ContextMenuTrigger asChild>
<div
data-workspace-focus-session-id={session.id}
draggable
role="button"
tabIndex={0}
className={cn(
'relative flex w-full select-none items-center justify-start gap-2 rounded-md px-2 py-1.5 text-sm font-normal outline-none transition-colors hover:text-inherit focus-visible:ring-1',
isDragging && 'opacity-50',
)}
style={{
backgroundColor: restBg,
color: rowFg,
boxShadow: dropPosition
? `inset 0 ${dropPosition === 'before' ? '2px' : '-2px'} 0 ${termFg}`
: undefined,
}}
onContextMenu={() => onSelect(session.id)}
onDragStart={(event) => onDragStart(event, session.id)}
onDragOver={(event) => onDragOver(event, session.id)}
onDragLeave={(event) => {
event.stopPropagation();
}}
onDrop={(event) => onDrop(event, session.id)}
onDragEnd={onDragEnd}
onMouseEnter={(event) => {
event.currentTarget.style.backgroundColor = hoverBg;
}}
onMouseLeave={(event) => {
event.currentTarget.style.backgroundColor = restBg;
}}
onClick={() => onSelect(session.id)}
onKeyDown={(event) => {
if (event.key !== 'Enter' && event.key !== ' ') return;
event.preventDefault();
onSelect(session.id);
}}
>
<div className="relative flex h-6 w-6 shrink-0 items-center justify-center self-center">
{host ? (
<DistroAvatar
host={host}
fallback={session.hostLabel}
size="sm"
className="!h-6 !w-6"
/>
) : (
<Server size={14} style={{ color: mutedFg }} />
)}
<Circle
size={5}
className={cn('absolute bottom-0 right-0 fill-current', statusColor)}
/>
</div>
<div className="flex h-6 flex-1 min-w-0 flex-col justify-center self-center text-left">
{isRenaming ? (
<SessionInlineRenameInput
initialName={renameValue}
onCommit={onSubmitRename}
onCancel={onCancelRename}
className="h-5 text-xs leading-none"
/>
) : (
<>
<div
className={cn('truncate text-xs leading-none', isSelected ? 'font-semibold' : 'font-medium')}
onDoubleClick={(e) => {
e.stopPropagation();
onStartRename(session.id);
}}
>
{session.customName || session.hostLabel}
</div>
<div className="mt-0.5 truncate text-[10px] leading-none" style={{ color: mutedFg }}>
{session.username}@{session.hostname}
</div>
</>
)}
</div>
</div>
</ContextMenuTrigger>
<SessionTabContextMenuContent
sessionId={session.id}
onCloseSession={onCloseSession}
onCopySession={onCopySession}
onCopySessionToNewWindow={onCopySessionToNewWindow}
onDetachSession={onDetachSessionFromWorkspace}
onRenameSession={onStartRename}
t={t}
/>
</ContextMenu>
);
}, (prev, next) => (
prev.session === next.session
&& prev.host === next.host
&& prev.isSelected === next.isSelected
&& prev.isRenaming === next.isRenaming
&& prev.renameValue === next.renameValue
&& prev.isDragging === next.isDragging
&& prev.dropPosition === next.dropPosition
&& prev.theme === next.theme
&& prev.onSelect === next.onSelect
&& prev.onStartRename === next.onStartRename
&& prev.onSubmitRename === next.onSubmitRename
&& prev.onCancelRename === next.onCancelRename
&& prev.onCloseSession === next.onCloseSession
&& prev.onCopySession === next.onCopySession
&& prev.onCopySessionToNewWindow === next.onCopySessionToNewWindow
&& prev.onDetachSessionFromWorkspace === next.onDetachSessionFromWorkspace
&& prev.onDragStart === next.onDragStart
&& prev.onDragOver === next.onDragOver
&& prev.onDrop === next.onDrop
&& prev.onDragEnd === next.onDragEnd
&& prev.t === next.t
));
WorkspaceFocusSessionRow.displayName = 'WorkspaceFocusSessionRow';
const TerminalFocusSidebarInner: React.FC<TerminalFocusSidebarProps> = ({
activeWorkspace,
focusedSessionId,
onReorderWorkspaceSessions,
onRequestAddToWorkspace,
onCloseSession,
onCopySession,
onCopySessionToNewWindow,
onDetachSessionFromWorkspace,
onSetWorkspaceFocusedSession,
onToggleWorkspaceViewMode,
onSubmitSessionRename,
resolvedPreviewTheme,
sessionHostsMap,
sessions,
t,
}) => {
const [focusSidebarSearch, setFocusSidebarSearch] = useState('');
const [focusSidebarDragSessionId, setFocusSidebarDragSessionId] = useState<string | null>(null);
const [focusSidebarDropIndicator, setFocusSidebarDropIndicator] = useState<{
sessionId: string;
position: 'before' | 'after';
} | null>(null);
const [focusSidebarWidth, setFocusSidebarWidth, persistFocusSidebarWidth] = useStoredNumber(
STORAGE_KEY_WORKSPACE_FOCUS_SIDEBAR_WIDTH, 224, { min: 160, max: 480 },
);
const [sidebarRenameSessionId, setSidebarRenameSessionId] = useState<string | null>(null);
const [sidebarRenameValue, setSidebarRenameValue] = useState('');
const theme = useMemo<FocusSidebarTheme>(() => {
const termBg = resolvedPreviewTheme.colors.background;
const termFg = resolvedPreviewTheme.colors.foreground;
return {
termBg,
termFg,
selectedBg: `color-mix(in srgb, ${termFg} 10%, transparent)`,
selectedHoverBg: `color-mix(in srgb, ${termFg} 15%, transparent)`,
unselectedHoverBg: `color-mix(in srgb, ${termFg} 10%, transparent)`,
unselectedFg: `color-mix(in srgb, ${termFg} 75%, ${termBg} 25%)`,
mutedFg: `color-mix(in srgb, ${termFg} 55%, ${termBg} 45%)`,
separator: `color-mix(in srgb, ${termFg} 10%, ${termBg} 90%)`,
};
}, [resolvedPreviewTheme]);
const workspaceSessions = useMemo(() => {
const sessionMap = new Map(sessions.map((session) => [session.id, session]));
return resolveWorkspaceFocusSessionOrder(activeWorkspace.root, activeWorkspace.focusSessionOrder)
.map((sessionId) => sessionMap.get(sessionId))
.filter((session): session is TerminalSession => Boolean(session));
}, [activeWorkspace, sessions]);
const visibleSessions = useMemo(() => {
const term = focusSidebarSearch.trim().toLowerCase();
if (!term) return workspaceSessions;
return workspaceSessions.filter((session) => (
session.customName?.toLowerCase().includes(term)
|| session.hostLabel?.toLowerCase().includes(term)
|| session.hostname?.toLowerCase().includes(term)
|| session.username?.toLowerCase().includes(term)
));
}, [focusSidebarSearch, workspaceSessions]);
const handleFocusSidebarResizeStart = useCallback((event: MouseEvent) => {
event.preventDefault();
const startX = event.clientX;
const startWidth = focusSidebarWidth;
let lastWidth = startWidth;
let rafId: number | null = null;
const onMouseMove = (moveEvent: MouseEvent) => {
const delta = moveEvent.clientX - startX;
lastWidth = Math.max(160, Math.min(480, startWidth + delta));
if (rafId !== null) return;
rafId = requestAnimationFrame(() => {
rafId = null;
setFocusSidebarWidth(lastWidth);
});
};
const onMouseUp = () => {
if (rafId !== null) cancelAnimationFrame(rafId);
setFocusSidebarWidth(lastWidth);
persistFocusSidebarWidth(lastWidth);
window.removeEventListener('mousemove', onMouseMove);
window.removeEventListener('mouseup', onMouseUp);
};
window.addEventListener('mousemove', onMouseMove);
window.addEventListener('mouseup', onMouseUp);
}, [focusSidebarWidth, persistFocusSidebarWidth, setFocusSidebarWidth]);
const handleFocusSidebarDragStart = useCallback((event: DragEvent, sessionId: string) => {
event.stopPropagation();
event.dataTransfer.effectAllowed = 'move';
event.dataTransfer.setData('workspace-focus-session-id', sessionId);
setFocusSidebarDragSessionId(sessionId);
}, []);
const getFocusSidebarContainerDropTarget = useCallback((
container: HTMLElement,
clientY: number,
draggedSessionId: string,
): { sessionId: string; position: 'before' | 'after' } | null => {
const rows = Array.from(
container.querySelectorAll<HTMLElement>('[data-workspace-focus-session-id]'),
);
if (rows.length === 0) return null;
for (const row of rows) {
const sessionId = row.dataset.workspaceFocusSessionId;
if (!sessionId || sessionId === draggedSessionId) continue;
const rect = row.getBoundingClientRect();
if (clientY < rect.top) return { sessionId, position: 'before' };
if (clientY <= rect.bottom) {
return {
sessionId,
position: clientY < rect.top + rect.height / 2 ? 'before' : 'after',
};
}
}
const lastRow = [...rows].reverse().find((row) => (
row.dataset.workspaceFocusSessionId
&& row.dataset.workspaceFocusSessionId !== draggedSessionId
));
const lastSessionId = lastRow?.dataset.workspaceFocusSessionId;
return lastSessionId ? { sessionId: lastSessionId, position: 'after' } : null;
}, []);
const handleFocusSidebarDragOver = useCallback((event: DragEvent, targetSessionId: string) => {
const draggedSessionId = event.dataTransfer.getData('workspace-focus-session-id') || focusSidebarDragSessionId;
if (!draggedSessionId || draggedSessionId === targetSessionId) return;
event.preventDefault();
event.stopPropagation();
event.dataTransfer.dropEffect = 'move';
const rect = event.currentTarget.getBoundingClientRect();
const position = event.clientY < rect.top + rect.height / 2 ? 'before' : 'after';
setFocusSidebarDropIndicator({ sessionId: targetSessionId, position });
}, [focusSidebarDragSessionId]);
const handleFocusSidebarContainerDragOver = useCallback((event: DragEvent<HTMLDivElement>) => {
const draggedSessionId = event.dataTransfer.getData('workspace-focus-session-id') || focusSidebarDragSessionId;
if (!draggedSessionId) return;
const target = getFocusSidebarContainerDropTarget(event.currentTarget, event.clientY, draggedSessionId);
if (!target) return;
event.preventDefault();
event.dataTransfer.dropEffect = 'move';
setFocusSidebarDropIndicator(target);
}, [focusSidebarDragSessionId, getFocusSidebarContainerDropTarget]);
const handleFocusSidebarContainerDrop = useCallback((event: DragEvent<HTMLDivElement>) => {
const draggedSessionId = event.dataTransfer.getData('workspace-focus-session-id') || focusSidebarDragSessionId;
if (!draggedSessionId) return;
const target = focusSidebarDropIndicator
?? getFocusSidebarContainerDropTarget(event.currentTarget, event.clientY, draggedSessionId);
if (!target || target.sessionId === draggedSessionId) return;
event.preventDefault();
onReorderWorkspaceSessions?.(activeWorkspace.id, draggedSessionId, target.sessionId, target.position);
setFocusSidebarDragSessionId(null);
setFocusSidebarDropIndicator(null);
}, [
activeWorkspace.id,
focusSidebarDragSessionId,
focusSidebarDropIndicator,
getFocusSidebarContainerDropTarget,
onReorderWorkspaceSessions,
]);
const handleFocusSidebarDrop = useCallback((event: DragEvent, targetSessionId: string) => {
const draggedSessionId = event.dataTransfer.getData('workspace-focus-session-id') || focusSidebarDragSessionId;
if (!draggedSessionId || draggedSessionId === targetSessionId) return;
event.preventDefault();
event.stopPropagation();
const rect = event.currentTarget.getBoundingClientRect();
const position = focusSidebarDropIndicator?.sessionId === targetSessionId
? focusSidebarDropIndicator.position
: event.clientY < rect.top + rect.height / 2 ? 'before' : 'after';
onReorderWorkspaceSessions?.(activeWorkspace.id, draggedSessionId, targetSessionId, position);
setFocusSidebarDragSessionId(null);
setFocusSidebarDropIndicator(null);
}, [activeWorkspace.id, focusSidebarDragSessionId, focusSidebarDropIndicator, onReorderWorkspaceSessions]);
const handleFocusSidebarDragEnd = useCallback(() => {
setFocusSidebarDragSessionId(null);
setFocusSidebarDropIndicator(null);
}, []);
const handleSelectSession = useCallback((sessionId: string) => {
onSetWorkspaceFocusedSession?.(activeWorkspace.id, sessionId);
}, [activeWorkspace.id, onSetWorkspaceFocusedSession]);
const handleLocalStartRename = useCallback((sessionId: string) => {
const session = sessions.find((s) => s.id === sessionId);
if (!session) return;
setSidebarRenameSessionId(sessionId);
setSidebarRenameValue(session.customName || session.hostLabel || '');
}, [sessions]);
const handleLocalSubmitRename = useCallback((name: string) => {
if (!sidebarRenameSessionId) return;
onSubmitSessionRename(sidebarRenameSessionId, name);
setSidebarRenameSessionId(null);
setSidebarRenameValue('');
}, [sidebarRenameSessionId, onSubmitSessionRename]);
const handleLocalCancelRename = useCallback(() => {
setSidebarRenameSessionId(null);
setSidebarRenameValue('');
}, []);
return (
<div
className="flex-shrink-0 flex flex-col relative"
style={{
width: focusSidebarWidth,
backgroundColor: theme.termBg,
color: theme.termFg,
['--terminal-workspace-sidebar-border' as string]: `1px solid ${theme.separator}`,
}}
data-section="terminal-workspace-sidebar"
>
<div
className="absolute top-0 right-[-3px] h-full w-2 cursor-ew-resize z-30"
onMouseDown={handleFocusSidebarResizeStart}
/>
<div
className="h-9 flex items-center gap-1 px-1.5 flex-shrink-0"
style={{ borderBottom: `1px solid ${theme.separator}` }}
>
<div className="relative flex-1 min-w-0">
<Search
size={12}
className="absolute left-1 top-1/2 -translate-y-1/2 pointer-events-none"
style={{ color: theme.mutedFg }}
/>
<Input
value={focusSidebarSearch}
onChange={(event) => setFocusSidebarSearch(event.target.value)}
placeholder="Search terminals..."
className="h-7 pl-6 pr-1 text-xs bg-transparent border-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0"
style={{ color: theme.termFg }}
/>
</div>
{onRequestAddToWorkspace && (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-7 w-7 p-0 flex-shrink-0 hover:bg-transparent hover:text-inherit"
style={{ color: theme.mutedFg }}
onClick={() => onRequestAddToWorkspace(activeWorkspace.id)}
>
<Plus size={14} />
</Button>
</TooltipTrigger>
<TooltipContent>{t('terminal.layer.addTerminal')}</TooltipContent>
</Tooltip>
)}
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-7 w-7 p-0 flex-shrink-0 hover:bg-transparent hover:text-inherit"
style={{ color: theme.mutedFg }}
onClick={() => onToggleWorkspaceViewMode?.(activeWorkspace.id)}
>
<Columns2 size={14} />
</Button>
</TooltipTrigger>
<TooltipContent>{t('terminal.layer.switchToSplitView')}</TooltipContent>
</Tooltip>
</div>
<ScrollArea className="flex-1">
<div
className="p-2 space-y-1"
onDragOver={handleFocusSidebarContainerDragOver}
onDrop={handleFocusSidebarContainerDrop}
>
{visibleSessions.map((session) => (
<WorkspaceFocusSessionRow
key={session.id}
session={session}
host={sessionHostsMap.get(session.id)}
isSelected={session.id === focusedSessionId}
isRenaming={sidebarRenameSessionId === session.id}
renameValue={sidebarRenameValue}
onStartRename={handleLocalStartRename}
onSubmitRename={handleLocalSubmitRename}
onCancelRename={handleLocalCancelRename}
onCloseSession={onCloseSession}
onCopySession={onCopySession}
onCopySessionToNewWindow={onCopySessionToNewWindow}
onDetachSessionFromWorkspace={onDetachSessionFromWorkspace}
isDragging={focusSidebarDragSessionId === session.id}
dropPosition={
focusSidebarDropIndicator?.sessionId === session.id
? focusSidebarDropIndicator.position
: null
}
theme={theme}
onSelect={handleSelectSession}
onDragStart={handleFocusSidebarDragStart}
onDragOver={handleFocusSidebarDragOver}
onDrop={handleFocusSidebarDrop}
onDragEnd={handleFocusSidebarDragEnd}
t={t}
/>
))}
</div>
</ScrollArea>
</div>
);
};
function terminalFocusSidebarPropsEqual(
prev: TerminalFocusSidebarProps,
next: TerminalFocusSidebarProps,
): boolean {
if (prev.focusedSessionId !== next.focusedSessionId) return false;
if (prev.onSubmitSessionRename !== next.onSubmitSessionRename) return false;
if (prev.onCloseSession !== next.onCloseSession) return false;
if (prev.onCopySession !== next.onCopySession) return false;
if (prev.onCopySessionToNewWindow !== next.onCopySessionToNewWindow) return false;
if (prev.onDetachSessionFromWorkspace !== next.onDetachSessionFromWorkspace) return false;
if (prev.resolvedPreviewTheme !== next.resolvedPreviewTheme) return false;
if (prev.sessionHostsMap !== next.sessionHostsMap) return false;
if (prev.sessions !== next.sessions) return false;
if (prev.t !== next.t) return false;
if (prev.onReorderWorkspaceSessions !== next.onReorderWorkspaceSessions) return false;
if (prev.onRequestAddToWorkspace !== next.onRequestAddToWorkspace) return false;
if (prev.onSetWorkspaceFocusedSession !== next.onSetWorkspaceFocusedSession) return false;
if (prev.onToggleWorkspaceViewMode !== next.onToggleWorkspaceViewMode) return false;
const prevWs = prev.activeWorkspace;
const nextWs = next.activeWorkspace;
return (
prevWs.id === nextWs.id
&& prevWs.viewMode === nextWs.viewMode
&& prevWs.root === nextWs.root
&& prevWs.focusSessionOrder === nextWs.focusSessionOrder
);
}
export const TerminalFocusSidebar = memo(TerminalFocusSidebarInner, terminalFocusSidebarPropsEqual);
TerminalFocusSidebar.displayName = 'TerminalFocusSidebar';