Files
Netcatty/components/terminalLayer/TerminalLayerView.tsx
T
陈大猫andCursor 36e5779d94 perf(terminal): reduce terminal tab-switch and layout jank (#1321)
* perf(terminal): smooth layout drags and faster tab switching

Defer xterm refit during split, sidebar, and host-tree drags while keeping pane containers in sync with live layout measurements. Refactor TerminalLayer into focused sections with TabBridge/memo optimizations and add the terminal host tree sidebar.

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

* fix(terminal): keep side panels alive and guard session attach races

Prevent terminal boot unmount from leaking backend sessions, keep SFTP/scripts/theme/AI state when switching side tabs, and defer heavy SFTP UI mount so first entry stays responsive.

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

* perf(terminal): reduce tab switch jank

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 03:35:03 +08:00

65 lines
2.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { memo } from 'react';
import { TerminalLayerFocusSidebarSection } from './TerminalLayerFocusSidebarSection';
import { TerminalLayerHostTreeSection } from './TerminalLayerHostTreeSection';
import { TerminalLayerSidePanelSection } from './TerminalLayerSidePanelSection';
import { TerminalLayerWorkspaceSection } from './TerminalLayerWorkspaceSection';
import { terminalLayerViewCtxEqual } from './terminalLayerViewMemo';
type TerminalLayerViewContext = Record<string, any>;
function TerminalLayerViewInner({ ctx }: { ctx: TerminalLayerViewContext }) {
const {
activeWorkspace,
composeBarThemeColors,
focusedSessionId,
handleComposeSend,
isBroadcastEnabled,
isComposeBarOpen,
isTerminalLayerVisible,
refocusTerminalSession,
setIsComposeBarOpen,
TerminalComposeBar,
workspaceOuterRef,
} = ctx;
return (
<div
ref={workspaceOuterRef}
className="absolute inset-0 bg-background flex flex-col"
data-section="terminal-workspace"
style={{
visibility: isTerminalLayerVisible ? 'visible' : 'hidden',
pointerEvents: isTerminalLayerVisible ? 'auto' : 'none',
zIndex: isTerminalLayerVisible ? 10 : 0,
}}
>
<div className="flex-1 flex min-h-0 relative">
<TerminalLayerHostTreeSection ctx={ctx} />
<TerminalLayerSidePanelSection ctx={ctx} />
<TerminalLayerFocusSidebarSection ctx={ctx} />
<TerminalLayerWorkspaceSection ctx={ctx} />
</div>
{activeWorkspace && isComposeBarOpen && (
<TerminalComposeBar
onSend={handleComposeSend}
onClose={() => {
setIsComposeBarOpen(false);
refocusTerminalSession(focusedSessionId);
}}
isBroadcastEnabled={isBroadcastEnabled?.(activeWorkspace.id)}
themeColors={composeBarThemeColors}
/>
)}
</div>
);
}
export const TerminalLayerView = memo(
TerminalLayerViewInner,
(prev, next) => terminalLayerViewCtxEqual(prev.ctx, next.ctx),
);
TerminalLayerView.displayName = 'TerminalLayerView';