Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions packages/devtools/src/utils/layout-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import {
allGroups,
appendPane,
canSplit,
closeGroup,
closeTab,
flattenTabs,
insertionIndex,
layoutRects,
moveTab,
nextGroupId,
paneRects,
repairLayout,
resetSplit,
resize,
Expand Down Expand Up @@ -154,20 +151,6 @@ describe('closeTab', () => {
})
})

describe('closeGroup', () => {
it('removes every tab in the group and prunes', () => {
const tree = split('row', [group('g0', ['a', 'b']), group('g1', ['c'])])
const next = closeGroup(tree, 'g0')
expect(next).toEqual(group('g1', ['c'], 0))
expectWellFormed(next)
})

it('is a no-op for an unknown group', () => {
const tree = group('g0', ['a'])
expect(closeGroup(tree, 'gX')).toEqual(tree)
})
})

describe('activateTab', () => {
it('selects without moving', () => {
const next = activateTab(group('g0', ['a', 'b', 'c']), 'c')
Expand Down Expand Up @@ -485,17 +468,8 @@ describe('layoutRects', () => {
})
})

it('gives every tab in a group the group rect', () => {
const tree = split('row', [group('g0', ['a', 'b']), group('g1', ['c'])])
const rects = paneRects(tree, BOX)
expect(rects.a).toEqual(rects.b)
expect(rects.a).toEqual({ left: 0, top: 0, width: 500, height: 400 })
expect(rects.c!.left).toBe(500)
})

it('returns nothing for an empty tree', () => {
expect(layoutRects(null, BOX)).toEqual({})
expect(paneRects(null, BOX)).toEqual({})
})
})

Expand Down Expand Up @@ -769,29 +743,6 @@ describe('zoneAt', () => {
})
})

describe('insertionIndex', () => {
const tabs = [
{ left: 0, top: 0, width: 100, height: 30 },
{ left: 100, top: 0, width: 100, height: 30 },
{ left: 200, top: 0, width: 100, height: 30 },
]

it('inserts before a tab in its first half', () => {
expect(insertionIndex(10, tabs)).toBe(0)
expect(insertionIndex(120, tabs)).toBe(1)
})

it('inserts after a tab in its second half', () => {
expect(insertionIndex(80, tabs)).toBe(1)
expect(insertionIndex(180, tabs)).toBe(2)
})

it('appends past the end and handles an empty bar', () => {
expect(insertionIndex(999, tabs)).toBe(3)
expect(insertionIndex(0, [])).toBe(0)
})
})

describe('repairLayout', () => {
const known = new Set(['a', 'b', 'c'])

Expand Down
38 changes: 0 additions & 38 deletions packages/devtools/src/utils/layout-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,6 @@ export const closeTab = (
return tree === null ? null : prune(strip(tree))
}

/** Remove a whole group and everything in it. */
export const closeGroup = (
tree: LayoutNode | null,
groupId: string,
): LayoutNode | null => {
const group = findGroupById(tree, groupId)
if (group === null) return tree
return group.tabs.reduce<LayoutNode | null>(
(acc, tabId) => closeTab(acc, tabId),
tree,
)
}

/**
* Replace a group's tab order wholesale, keeping the same tab selected.
*
Expand Down Expand Up @@ -583,21 +570,6 @@ export const splitterHandles = (
return handles
}

/** Rect per plugin id, which is what the panes are keyed by. */
export const paneRects = (
tree: LayoutNode | null,
box: Size,
gutter = 0,
): Record<string, Rect> => {
const byGroup = layoutRects(tree, box, gutter)
const out: Record<string, Rect> = {}
for (const group of allGroups(tree)) {
const rect = byGroup[group.id]
if (rect) for (const tabId of group.tabs) out[tabId] = rect
}
return out
}

/**
* Whether splitting a group leaves both halves at least `min`. The workspace is
* short, so a split that would produce an unreadable cell is refused and the
Expand Down Expand Up @@ -639,16 +611,6 @@ export const zoneAt = (
return distance <= edge ? zone : 'center'
}

/** Insertion index for a tab dropped at `x` over a row of tab rects. */
export const insertionIndex = (x: number, tabs: Array<Rect>): number => {
let index = 0
for (const rect of tabs) {
if (x < rect.left + rect.width / 2) break
index += 1
}
return index
}

const isRawGroup = (value: Record<string, unknown>): boolean =>
value.kind === 'group' &&
typeof value.id === 'string' &&
Expand Down