MCPcopy
hub / github.com/coder/mux / reorderTabInTabset

Function reorderTabInTabset

src/browser/utils/rightSidebarLayout.ts:302–339  ·  view source on GitHub ↗
(
  state: RightSidebarLayoutState,
  tabsetId: string,
  fromIndex: number,
  toIndex: number
)

Source from the content-addressed store, hash-verified

300}
301
302export function reorderTabInTabset(
303 state: RightSidebarLayoutState,
304 tabsetId: string,
305 fromIndex: number,
306 toIndex: number
307): RightSidebarLayoutState {
308 const tabset = findTabset(state.root, tabsetId);
309 if (tabset?.type !== "tabset") {
310 return state;
311 }
312
313 if (
314 fromIndex === toIndex ||
315 fromIndex < 0 ||
316 toIndex < 0 ||
317 fromIndex >= tabset.tabs.length ||
318 toIndex >= tabset.tabs.length
319 ) {
320 return state;
321 }
322
323 return {
324 ...state,
325 root: updateNode(state.root, tabsetId, (node) => {
326 const nextTabs = [...node.tabs];
327 const [moved] = nextTabs.splice(fromIndex, 1);
328 if (!moved) {
329 return node;
330 }
331
332 nextTabs.splice(toIndex, 0, moved);
333 return {
334 ...node,
335 tabs: nextTabs,
336 };
337 }),
338 };
339}
340
341export function selectTabInFocusedTabset(
342 state: RightSidebarLayoutState,

Callers 2

RightSidebarComponentFunction · 0.90

Calls 2

updateNodeFunction · 0.85
findTabsetFunction · 0.70

Tested by

no test coverage detected