MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / reorder

Function reorder

frontend/app/tab/vtabbar.tsx:297–316  ·  view source on GitHub ↗
(targetIndex: number)

Source from the content-addressed store, hash-verified

295 };
296
297 const reorder = (targetIndex: number) => {
298 const sourceTabId = dragSourceRef.current;
299 if (sourceTabId == null) {
300 return;
301 }
302 const sourceIndex = orderedTabIds.findIndex((id) => id === sourceTabId);
303 if (sourceIndex === -1) {
304 return;
305 }
306 const boundedTargetIndex = Math.max(0, Math.min(targetIndex, orderedTabIds.length));
307 const adjustedTargetIndex = sourceIndex < boundedTargetIndex ? boundedTargetIndex - 1 : boundedTargetIndex;
308 if (sourceIndex === adjustedTargetIndex) {
309 return;
310 }
311 const nextTabIds = [...orderedTabIds];
312 const [movedId] = nextTabIds.splice(sourceIndex, 1);
313 nextTabIds.splice(adjustedTargetIndex, 0, movedId);
314 setOrderedTabIds(nextTabIds);
315 fireAndForget(() => env.rpc.UpdateWorkspaceTabIdsCommand(TabRpcClient, workspace.oid, nextTabIds));
316 };
317
318 const handleTabBarContextMenu = useCallback(
319 (e: React.MouseEvent<HTMLDivElement>) => {

Callers 1

VTabBarFunction · 0.85

Calls 2

fireAndForgetFunction · 0.90

Tested by

no test coverage detected