diff --git a/e2e/editor.spec.ts b/e2e/editor.spec.ts index 4809b0c7c..1eb7ad204 100644 --- a/e2e/editor.spec.ts +++ b/e2e/editor.spec.ts @@ -133,6 +133,64 @@ test("breadcrumbs follow the caret into the symbol under it", async ({ workbench await expect(bar).toBeHidden(); }); +test("narrow breadcrumb bars keep the current symbol visible and allow opening earlier crumbs", async ({ + workbench: page, +}) => { + const editor = await openFromTree(page, "build.gradle.kts"); + const path = page.getByRole("navigation", { name: "Breadcrumbs", exact: true }); + const code = page.getByRole("navigation", { name: "Code breadcrumbs" }); + await editor.locator(".cm-line", { hasText: "service.find(status" }).click(); + await expect(code).toContainText("list()"); + + await page.evaluate(async () => { + const documentModule = "/src/editor/core/model/document.ts"; + const editorModule = "/src/editor/core/controller.ts"; + const projectModule = "/src/platform/project.ts"; + const schemaModule = "/src/features/settings/model/schema.ts"; + const [{ useOutline }, { useEditorStatus }, { useProject }, { DEFAULT_SETTINGS }] = await Promise.all([ + import(/* @vite-ignore */ documentModule), + import(/* @vite-ignore */ editorModule), + import(/* @vite-ignore */ projectModule), + import(/* @vite-ignore */ schemaModule), + ]); + const base = useProject.getState().settings ?? DEFAULT_SETTINGS; + useProject.setState({ settings: { ...base, editor: { ...base.editor, fontSize: 17 } } }); + const activePath = useEditorStatus.getState().status.path; + let outline = useOutline.getState()[activePath]; + for (const name of ["OrderProcessingStrategies", "SalesApplicationRouting", "CheckoutWorkspaceConfiguration"]) { + outline = [{ ...outline[0], name, detail: null, children: outline }]; + } + useOutline.setState({ [activePath]: outline }); + }); + + await page.setViewportSize({ width: 620, height: 620 }); + const fullyInBar = (bar: typeof path, label: string) => + bar.evaluate((nav, text) => { + const crumb = [...nav.querySelectorAll("button")].find((button) => button.textContent === text); + if (!crumb) return false; + const { left, right } = nav.getBoundingClientRect(); + const rect = crumb.getBoundingClientRect(); + return rect.width > 0 && rect.left >= left - 1 && rect.right <= right + 1; + }, label); + for (const bar of [path, code]) { + await expect.poll(() => fullyInBar(bar, "list()")).toBe(true); + await expect(bar.locator('[aria-current="location"]')).toHaveText("list()"); + } + await expect(code.locator('[aria-current="location"]')).toHaveCSS("font-size", "17px"); + await code.hover(); + await page.mouse.wheel(0, -1200); + await expect.poll(() => fullyInBar(code, "CheckoutWorkspaceConfiguration")).toBe(true); + + const current = path.locator('[aria-current="location"]'); + await current.focus(); + await current.press("Home"); + const project = path.getByRole("button", { name: /acme-api/ }).first(); + await expect(project).toBeFocused(); + await expect.poll(() => fullyInBar(path, "acme-api")).toBe(true); + await project.press("ArrowDown"); + await expect(page.getByRole("listbox", { name: "acme-api" })).toBeVisible(); +}); + /** What the in-memory backend has saved for `path`. */ const saved = (page: Page, path: string) => page.evaluate(async (path) => { diff --git a/src/editor/core/view/EditorArea.module.css b/src/editor/core/view/EditorArea.module.css index 20003e0a7..e491b6ae3 100644 --- a/src/editor/core/view/EditorArea.module.css +++ b/src/editor/core/view/EditorArea.module.css @@ -218,15 +218,44 @@ min-width: 0; overflow: hidden; } -.crumbButton { - flex: none; - max-width: 240px; - gap: 5px; - color: var(--fg); -} -.crumbButton:last-child { - flex: 0 1 auto; +.crumbStrip { + display: flex; + align-items: center; min-width: 0; + overflow-x: auto; + overflow-y: hidden; + scrollbar-width: none; +} +.crumbStrip::-webkit-scrollbar { + display: none; +} +.crumbStrip:is([data-crumbs-before], [data-crumbs-after]) { + --crumb-mask: linear-gradient( + to right, + var(--crumb-start, black), + black var(--space-3), + black calc(100% - var(--space-3)), + var(--crumb-end, black) + ); + -webkit-mask-image: var(--crumb-mask); + mask-image: var(--crumb-mask); +} +.crumbStrip[data-crumbs-before] { + --crumb-start: transparent; +} +.crumbStrip[data-crumbs-after] { + --crumb-end: transparent; +} +.crumbStrip .crumbButton { + flex: none; + max-width: min(240px, 100%); + margin: 0; + padding: 0 var(--space-1); + font: inherit; + color: inherit; +} +.crumbStrip .crumbButton[aria-current="location"] { + color: var(--fg); } .crumbIcon { flex: none; @@ -240,7 +269,6 @@ .statusSep { flex: none; color: var(--fg-faint); - margin: 0 2px; } .lock { display: inline-flex; @@ -339,13 +367,23 @@ flex: none; display: flex; align-items: center; - gap: var(--space-0-5); - height: 26px; - padding: 0 8px; + height: max(24px, calc(1em + var(--space-2))); + padding: 0 var(--space-2); overflow: hidden; background: var(--bg-editor, var(--bg-island)); color: var(--fg-muted); - font-size: var(--fs-small); + font-family: var(--font-mono); + font-size: var(--fs-code); +} +.codeCrumbs .crumbStrip { + gap: var(--space-0-5); +} +.codeCrumbs .crumbButton { + height: max(20px, calc(1em + var(--space-1))); + max-width: 100%; +} +.codeCrumbs .crumbButton[aria-current="location"] { + background: var(--bg-tree-selected-inactive); } .codeCrumbsTop { border-bottom: 1px solid var(--border-editor-tabs, var(--border)); diff --git a/src/editor/core/view/StatusItems.tsx b/src/editor/core/view/StatusItems.tsx index b58856c84..cf3eaaada 100644 --- a/src/editor/core/view/StatusItems.tsx +++ b/src/editor/core/view/StatusItems.tsx @@ -1,15 +1,16 @@ /** Status bar widgets of the active text editor (design footer). */ -import { Fragment, useRef, useState } from "react"; +import { Fragment, useLayoutEffect, useRef, useState, type ComponentPropsWithoutRef } from "react"; import clsx from "clsx"; import { useShallow } from "zustand/react/shallow"; import { executeAction } from "@/platform/actions"; import { shortcutLabel } from "@/platform/keymap"; import { basename, dirname, projectFolder, relativePath, useProject } from "@/platform/project"; import type { LineEnding, OutlineItem } from "@/platform/ipc"; -import { BarButton, Icon, Menu, badgeKind, fileIconName } from "@/ui"; +import { BarButton, Icon, Menu, badgeKind, fileIconName, revealHorizontally } from "@/ui"; import { notifications, useProjectViewLead } from "@/workbench/contributions"; import { useDistractionFree } from "@/workbench/distractionFree"; import { ENCODING_CHOICES, useEditorPrefs } from "@/platform/editorSettings"; +import { BUNDLED_MONO_FAMILY, monoFontFamily } from "@/platform/fonts"; import { gitRevisionOf, isUntitledUri, @@ -145,15 +146,39 @@ function pathCrumbs(project: { root: string; name: string } | null, path: string return segments; } -/** A row of crumbs; a segment with `nav` opens a popup of its children. */ -function CrumbNav({ segments, className, ariaLabel }: { segments: Crumb[]; className?: string; ariaLabel?: string }) { - const [popup, setPopup] = useState<{ nav: NavSegment; anchor: HTMLElement } | null>(null); +function updateBreadcrumbEdges(row: HTMLDivElement) { + row.toggleAttribute("data-crumbs-before", row.scrollLeft > 1); + row.toggleAttribute("data-crumbs-after", row.scrollLeft + row.clientWidth < row.scrollWidth - 1); +} + +function BreadcrumbStrip({ + trail, + activateOnDown = false, + children, + ...props +}: ComponentPropsWithoutRef<"nav"> & { trail: string; activateOnDown?: boolean }) { + const strip = useRef(null); + useLayoutEffect(() => { + const row = strip.current; + if (!row) return; + const revealCurrent = () => { + const focused = document.activeElement; + if (focused instanceof HTMLElement && row.contains(focused)) revealHorizontally(row, focused); + else row.scrollLeft = row.scrollWidth; + updateBreadcrumbEdges(row); + }; + revealCurrent(); + if (typeof ResizeObserver === "undefined") return; + const resize = new ResizeObserver(revealCurrent); + resize.observe(row); + return () => resize.disconnect(); + }, [trail]); return ( ); } +/** A row of crumbs; a segment with `nav` opens a popup of its children. */ +function CrumbNav({ segments, className }: { segments: Crumb[]; className?: string }) { + const [popup, setPopup] = useState<{ nav: NavSegment; anchor: HTMLElement } | null>(null); + return ( + s.title).join("\n")} + activateOnDown + className={className} + aria-label={tx("Breadcrumbs")} + > + {segments.map((s, i) => { + const current = i === segments.length - 1; + const icon = s.nav?.kind === "dir" && !s.nav.root && !current ? undefined : s.icon; + return ( + + {i > 0 && } + { + const nav = s.nav; + const anchor = e.currentTarget; + if (nav) setPopup((p) => (p?.anchor === anchor ? null : { nav, anchor })); + else s.run?.(); + }} + > + {icon && ( + + )} + {s.label} + + + ); + })} + {popup && setPopup(null)} />} + + ); +} + /** * IDEA new UI navigation bar (the top of the workbench, or the status bar * footer via `inStatusBar`): project › dirs › file › symbols, with icons; @@ -241,7 +300,7 @@ export function Breadcrumbs({ className, inStatusBar = false }: { className?: st segments.push(projectCrumb(project ?? currentProject)); } if (!segments.length) return null; - return ; + return ; } /** The status bar instance of the navigation bar; renders only for `statusBar`. */ @@ -262,7 +321,8 @@ export function CodeBreadcrumbs({ tabId: string; position: "top" | "bottom"; }) { - const prefs = useEditorPrefs().breadcrumbs; + const { breadcrumbs: prefs, fallbackFont } = useEditorPrefs(); + const editorSettings = useProject((s) => s.settings?.editor); const language = useDocMeta((s) => s[path]?.language); const outline = useOutline((s) => s[path]); let chain = useCaretSymbols(path, outline); @@ -278,29 +338,35 @@ export function CodeBreadcrumbs({ !chain.length ) return null; + const family = editorSettings?.fontFamily; + const fontFamily = + (family && family !== BUNDLED_MONO_FAMILY) || fallbackFont.trim() + ? monoFontFamily(family, fallbackFont, "var(--font-mono)") + : undefined; + const fontSize = editorSettings?.fontSize ?? undefined; return ( - + ); } diff --git a/src/workbench/StatusBar.module.css b/src/workbench/StatusBar.module.css index 51998fbb5..6f4dc7028 100644 --- a/src/workbench/StatusBar.module.css +++ b/src/workbench/StatusBar.module.css @@ -29,11 +29,14 @@ min-width: 0; padding: 0 4px; } -/* Left items (breadcrumbs…) give way first on narrow windows; right items move into the overflow popup. */ +/* Left items shrink on narrow windows; right items move into the overflow popup. */ .shrink { flex: 0 1 auto; overflow: hidden; } +.shrink[data-status-item="editor.breadcrumbs"]:not(:empty) { + min-width: min(152px, 28vw); +} .shrink > * { min-width: 0; overflow: hidden; diff --git a/src/workbench/StatusBar.tsx b/src/workbench/StatusBar.tsx index 55e905c49..617093382 100644 --- a/src/workbench/StatusBar.tsx +++ b/src/workbench/StatusBar.tsx @@ -112,22 +112,24 @@ export function StatusBar({ lightEdit = false }: { lightEdit?: boolean }) { return () => ro.disconnect(); }, []); useLayoutEffect(() => { + const leftHosts = [...(barRef.current?.querySelectorAll(":scope > [data-status-item]") ?? [])]; measure.current = () => { const bar = barRef.current; if (!bar) return; const css = getComputedStyle(bar); const gap = parseFloat(css.columnGap) || 0; const spacer = spacerRef.current; - // Left items shrink instead (down to their gap); the spacer keeps its minimum. - const leftShown = [...bar.querySelectorAll(":scope > [data-status-item]")].filter( - (el) => el.getClientRects().length > 0, - ).length; + const leftWidth = leftHosts.reduce( + (width, el) => + el.getClientRects().length ? width + (parseFloat(getComputedStyle(el).minWidth) || 0) + gap : width, + 0, + ); const available = bar.clientWidth - (parseFloat(css.paddingLeft) || 0) - (parseFloat(css.paddingRight) || 0) - (spacer ? parseFloat(getComputedStyle(spacer).minWidth) || 0 : 0) - - leftShown * gap; + leftWidth; const items = shownRight.map((i) => ({ id: i.id, priority: i.priority, @@ -146,6 +148,7 @@ export function StatusBar({ lightEdit = false }: { lightEdit?: boolean }) { } // The spacer changes width whenever an item comes or goes; the bar, when the window resizes. for (const el of [spacerRef.current, barRef.current, moreRef.current]) if (el) ro?.observe(el); + for (const el of leftHosts) ro?.observe(el); }); const renderLeft = (item: StatusItemContribution) => {