Files
Netcatty/components/terminalLayer/workspaceSplitResize.test.ts
T
陈大猫 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

55 lines
1.6 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
computeResizeBoundary,
computeSplitSizesFromDelta,
patchWorkspaceSplitSizes,
type WorkspaceResizeSession,
} from './workspaceSplitResize';
import type { Workspace } from '../../types';
const session: WorkspaceResizeSession = {
workspaceId: 'ws-1',
splitId: 'split-1',
index: 0,
direction: 'horizontal',
startSizes: [0.5, 0.5],
startArea: { x: 0, y: 0, w: 800, h: 600 },
startClient: { x: 0, y: 300 },
};
test('computeSplitSizesFromDelta keeps normalized sizes', () => {
const sizes = computeSplitSizesFromDelta(session, 60);
assert.equal(sizes.length, 2);
assert.ok(Math.abs(sizes[0] + sizes[1] - 1) < 0.0001);
assert.ok(sizes[0] > 0.5);
});
test('computeResizeBoundary moves down when dragging split divider downward', () => {
const base = computeResizeBoundary(session, 0);
const moved = computeResizeBoundary(session, 80);
assert.ok(base != null && moved != null);
assert.ok(moved > base);
});
test('patchWorkspaceSplitSizes updates only the targeted split node', () => {
const workspace: Workspace = {
id: 'ws-1',
title: 'ws-1',
root: {
id: 'split-1',
type: 'split',
direction: 'horizontal',
sizes: [0.5, 0.5],
children: [
{ id: 'pane-a', type: 'pane', sessionId: 'a' },
{ id: 'pane-b', type: 'pane', sessionId: 'b' },
],
},
};
const next = patchWorkspaceSplitSizes(workspace, 'split-1', [0.7, 0.3]);
assert.notEqual(next, workspace);
assert.deepEqual(next.root.type === 'split' ? next.root.sizes : null, [0.7, 0.3]);
});