[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
68
components/ui/virtualListMath.ts
Normal file
68
components/ui/virtualListMath.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Pure math for virtual lists and keyboard cursors.
|
||||
* Kept free of React so tests drive the same functions the pickers use.
|
||||
*/
|
||||
|
||||
export function clampScrollTop(
|
||||
scrollTop: number,
|
||||
totalHeight: number,
|
||||
viewportHeight: number,
|
||||
): number {
|
||||
const maxScroll = Math.max(0, totalHeight - Math.max(viewportHeight, 0));
|
||||
return Math.min(Math.max(0, scrollTop), maxScroll);
|
||||
}
|
||||
|
||||
export function getFixedSizeVirtualWindow({
|
||||
itemCount,
|
||||
itemHeight,
|
||||
scrollTop,
|
||||
viewportHeight,
|
||||
overscan,
|
||||
}: {
|
||||
itemCount: number;
|
||||
itemHeight: number;
|
||||
scrollTop: number;
|
||||
viewportHeight: number;
|
||||
overscan: number;
|
||||
}): { startIndex: number; endIndex: number; effectiveScrollTop: number; totalHeight: number } {
|
||||
const totalHeight = Math.max(0, itemCount * itemHeight);
|
||||
const effectiveScrollTop = clampScrollTop(scrollTop, totalHeight, viewportHeight);
|
||||
if (itemCount <= 0 || itemHeight <= 0) {
|
||||
return { startIndex: 0, endIndex: 0, effectiveScrollTop, totalHeight };
|
||||
}
|
||||
const startIndex = Math.max(0, Math.floor(effectiveScrollTop / itemHeight) - overscan);
|
||||
const visibleCount = Math.ceil(Math.max(viewportHeight, 1) / itemHeight) + overscan * 2;
|
||||
const endIndex = Math.min(itemCount, startIndex + visibleCount);
|
||||
return { startIndex, endIndex, effectiveScrollTop, totalHeight };
|
||||
}
|
||||
|
||||
/** Clamp a keyboard cursor into [0, length-1], or 0 when the list is empty. */
|
||||
export function clampListIndex(index: number, length: number): number {
|
||||
if (length <= 0) return 0;
|
||||
if (!Number.isFinite(index)) return 0;
|
||||
return Math.max(0, Math.min(Math.trunc(index), length - 1));
|
||||
}
|
||||
|
||||
/** Move a keyboard cursor by delta without ever landing on -1. */
|
||||
export function stepListIndex(index: number, length: number, delta: number): number {
|
||||
if (length <= 0) return 0;
|
||||
return clampListIndex(index + delta, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map selectable item indices to visual row indices for lists that interleave
|
||||
* non-selectable chrome (headers, hints, empty rows).
|
||||
*/
|
||||
export function buildItemIndexToVisualIndexMap(
|
||||
visualRows: ReadonlyArray<{ kind: string }>,
|
||||
itemKind = 'item',
|
||||
): Map<number, number> {
|
||||
const map = new Map<number, number>();
|
||||
let itemIndex = 0;
|
||||
visualRows.forEach((row, visualIndex) => {
|
||||
if (row.kind !== itemKind) return;
|
||||
map.set(itemIndex, visualIndex);
|
||||
itemIndex += 1;
|
||||
});
|
||||
return map;
|
||||
}
|
||||
Reference in New Issue
Block a user