Skip to content

Commit b94a305

Browse files
authored
fix(gui-plugins): align file tree guides with chevrons (#59884)
1 parent 950111f commit b94a305

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎packages/app/e2e/regression/review.spec.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ test("file tree expands Windows paths and scrolls long names in both directions"
474474
fileList: (path) => {
475475
if (path === "frontend\\" || path === "frontend") {
476476
return [
477+
fileNode(directory, "frontend/nested", "directory"),
477478
{ ...fileNode(directory, "frontend/app.ts"), path: "frontend\\app.ts" },
478479
{ ...fileNode(directory, longPath), path: `frontend\\${longFilename}` },
479480
// Short rows below the long one, so it can scroll out of view.
@@ -485,6 +486,8 @@ test("file tree expands Windows paths and scrolls long names in both directions"
485486
]
486487
}
487488

489+
if (path === "frontend/nested") return [fileNode(directory, "frontend/nested/child.ts")]
490+
488491
if (path) return []
489492

490493
return [
@@ -510,6 +513,36 @@ test("file tree expands Windows paths and scrolls long names in both directions"
510513
await frontend.click()
511514
await expect(frontend).toHaveAttribute("aria-expanded", "true")
512515

516+
const nested = panel.locator('[data-type="item"][data-item-path="frontend/nested/"]')
517+
await nested.click()
518+
const child = panel.locator('[data-type="item"][data-item-path="frontend/nested/child.ts"]')
519+
await expect(child).toBeVisible()
520+
await expect(child.locator('[data-item-section="spacing-item"]')).toHaveCount(2)
521+
522+
// Every ancestor guide runs through its folder's chevron, not just the first indentation level.
523+
const guideOffset = () =>
524+
child.evaluate((element) => {
525+
const root = element.getRootNode()
526+
527+
if (!(root instanceof ShadowRoot)) throw new Error("Expected the file tree's shadow root")
528+
529+
return Math.max(
530+
...Array.from(element.querySelectorAll<HTMLElement>('[data-item-section="spacing-item"]'), (guide) => {
531+
const folder = Array.from(root.querySelectorAll<HTMLElement>('[data-type="item"]')).find(
532+
(row) => row.dataset.itemPath === guide.dataset.ancestorPath,
533+
)!
534+
535+
const icon = folder.querySelector('[data-item-section="icon"]')!.getBoundingClientRect()
536+
const line = guide.getBoundingClientRect()
537+
const center = getComputedStyle(guide).direction === "rtl" ? line.right - 0.5 : line.left + 0.5
538+
539+
return Math.abs(center - (icon.left + icon.width / 2))
540+
}),
541+
)
542+
})
543+
544+
await expect.poll(guideOffset).toBeLessThanOrEqual(0.5)
545+
513546
const viewport = sidebar.locator('[data-slot="session-review-v2-sidebar-viewport"]')
514547
const longRow = panel.locator(`[data-type="item"][data-item-path="${longPath}"]`)
515548
const content = longRow.locator('[data-item-section="content"]')
@@ -553,6 +586,7 @@ test("file tree expands Windows paths and scrolls long names in both directions"
553586
await expect.poll(async () => (await scrollTree({})).left).toBeGreaterThan(0)
554587
await scrollTree({ left: 0, top: 0 })
555588
await viewport.evaluate((element) => element.setAttribute("dir", "rtl"))
589+
await expect.poll(guideOffset).toBeLessThanOrEqual(0.5)
556590
await expect.poll(() => statusInset(status, "left")).toBeLessThanOrEqual(24)
557591
await frontend.focus()
558592
await page.keyboard.press("ArrowRight")

‎packages/gui-plugins/src/file/pierre-tree.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ const TREE_UNSAFE_CSS = `
3939
/* Long rows scroll sideways rather than clip; every row is as wide as the widest one seen in this row set. */
4040
[data-file-tree-virtualized-list="true"] { width: max-content; min-width: max(100%, var(--file-tree-min-width, 0px)); }
4141
[data-item-section="spacing"] {
42-
margin-left: 0; margin-right: 0;
43-
margin-inline-start: calc(var(--trees-spacing-unit) * 0.5 + 1px);
44-
margin-inline-end: calc(var(--trees-item-row-gap) * -1);
42+
padding-left: 0;
43+
padding-inline-start: calc(var(--trees-icon-width) / 2 - 0.5px);
4544
}
4645
[data-item-section="spacing-item"] {
4746
border-left: none; margin-right: 0;
4847
border-inline-start: 1px solid var(--trees-indent-guide-bg);
49-
margin-inline-end: var(--trees-item-row-gap);
48+
margin-inline-end: calc(var(--trees-level-gap) - 1px);
49+
transform: none;
50+
}
51+
[data-item-section="spacing-item"] + [data-item-section="spacing-item"] {
52+
margin-left: 0;
53+
margin-inline-start: calc(var(--trees-item-row-gap) + var(--trees-icon-width) / 2 - 0.5px);
5054
}
5155
[data-type="item"][aria-expanded="false"] [data-item-section="icon"] > svg:first-child {
5256
transform: translateY(var(--trees-icon-nudge));

0 commit comments

Comments
 (0)