Files
Netcatty/domain/hostGroupTreeFlat.ts
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

57 lines
1.9 KiB
TypeScript

import type { GroupNode, Host } from '../types';
export type HostTreeFlatRow =
| { kind: 'group'; node: GroupNode; depth: number }
| { kind: 'host'; host: Host; depth: number };
export function hostTreeFlatRowKey(row: HostTreeFlatRow): string {
return row.kind === 'group' ? `g:${row.node.path}` : `h:${row.host.id}`;
}
export function flattenHostGroupTree(params: {
groupNodes: GroupNode[];
ungroupedHosts: Host[];
expandedPaths: Set<string>;
searchActive: boolean;
}): HostTreeFlatRow[] {
const rows: HostTreeFlatRow[] = [];
const walkGroup = (node: GroupNode, depth: number) => {
rows.push({ kind: 'group', node, depth });
const isExpanded = params.searchActive || params.expandedPaths.has(node.path);
if (!isExpanded) return;
const sortedHosts = [...node.hosts].sort((a, b) => a.label.localeCompare(b.label));
for (const host of sortedHosts) {
rows.push({ kind: 'host', host, depth: depth + 1 });
}
const childNodes = (Object.values(node.children) as GroupNode[])
.sort((a, b) => a.name.localeCompare(b.name));
for (const child of childNodes) {
walkGroup(child, depth + 1);
}
};
for (const node of params.groupNodes) {
walkGroup(node, 0);
}
const sortedUngrouped = [...params.ungroupedHosts].sort((a, b) => a.label.localeCompare(b.label));
for (const host of sortedUngrouped) {
rows.push({ kind: 'host', host, depth: 0 });
}
return rows;
}
export function hostTreeFlatRowContainsHost(row: HostTreeFlatRow, hostId: string | null | undefined): boolean {
if (!hostId) return false;
if (row.kind === 'host') return row.host.id === hostId;
return row.node.hosts.some((host) => host.id === hostId)
|| Object.values(row.node.children).some((child) => {
const childRow: HostTreeFlatRow = { kind: 'group', node: child as GroupNode, depth: 0 };
return hostTreeFlatRowContainsHost(childRow, hostId);
});
}