дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
Порівняти коміти
3
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
e5edba1986 | ||
|
|
98da80b2b3 | ||
|
|
7febc5270a |
No files matched your search
@@ -427,6 +427,70 @@ test("Find Usages from the editor context menu lists every usage by file and ope
|
||||
).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
|
||||
test("usage locations and preview stay readable as the available space changes", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1040, height: 760 });
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(
|
||||
({ file, other }) => {
|
||||
const locations = [
|
||||
{ path: file, range: { start: { line: 16, col: 8 }, end: { line: 16, col: 15 } } },
|
||||
{ path: file, range: { start: { line: 20, col: 27 }, end: { line: 20, col: 34 } } },
|
||||
{ path: other, range: { start: { line: 0, col: 0 }, end: { line: 0, col: 7 } } },
|
||||
];
|
||||
window.__ipc.handlers.lsp_references = () => ({
|
||||
locations,
|
||||
classified: [{ location: locations[2], kind: "code", text: "service.submit(order)" }],
|
||||
incomplete: null,
|
||||
librariesSkipped: true,
|
||||
});
|
||||
},
|
||||
{ file: FILE, other: `${ROOT}/domain/checkout/processing/calculations/PaymentProcessingService.kt` },
|
||||
);
|
||||
await caretAt(editor, page, "val order: Order", "service");
|
||||
await page.keyboard.press("Meta+Alt+F7");
|
||||
const popup = page.getByRole("dialog", { name: "Usages" });
|
||||
const scope = popup.getByRole("button", { name: "Scope" });
|
||||
const openWindow = popup.getByRole("button", { name: /^Open in Find Window/ });
|
||||
await expect(popup.getByTestId("usage-row")).toHaveCount(3);
|
||||
await popup.getByRole("button", { name: "Show Preview" }).click();
|
||||
const code = popup.getByRole("region", { name: "Preview" });
|
||||
await expect(code.locator(".cm-content")).toContainText("service.find(status");
|
||||
|
||||
await page.setViewportSize({ width: 480, height: 470 });
|
||||
const within = async (child: Locator, parent: Locator) => {
|
||||
const [c, p] = await Promise.all([child.boundingBox(), parent.boundingBox()]);
|
||||
return (
|
||||
!!c &&
|
||||
!!p &&
|
||||
c.x >= p.x - 1 &&
|
||||
c.y >= p.y - 1 &&
|
||||
c.x + c.width <= p.x + p.width + 1 &&
|
||||
c.y + c.height <= p.y + p.height + 1
|
||||
);
|
||||
};
|
||||
await expect.poll(() => within(scope, popup)).toBe(true);
|
||||
await expect.poll(() => within(openWindow, popup)).toBe(true);
|
||||
await expect.poll(() => within(code, popup)).toBe(true);
|
||||
const results = popup.getByRole("listbox", { name: "Usages" });
|
||||
await expect.poll(() => within(popup.getByTestId("usage-row").last(), results)).toBe(true);
|
||||
const firstRow = popup.getByTestId("usage-row").first();
|
||||
const file = firstRow.getByText("build.gradle.kts", { exact: true });
|
||||
await expect(file).toBeVisible();
|
||||
const [filename, snippet] = await Promise.all([file.boundingBox(), firstRow.locator("mark").boundingBox()]);
|
||||
expect(filename!.x + filename!.width).toBeLessThan(snippet!.x);
|
||||
await openWindow.click();
|
||||
|
||||
const tree = page.getByRole("tree", { name: "Usages" });
|
||||
const target = tree.getByRole("treeitem", { name: /^17 service\.find\(status/ });
|
||||
await target.click();
|
||||
const preview = page.getByRole("region", { name: "Preview" });
|
||||
await expect(preview).toContainText("service.find(status");
|
||||
await expect.poll(async () => (await preview.boundingBox())!.y > (await tree.boundingBox())!.y).toBe(true);
|
||||
await page.setViewportSize({ width: 1040, height: 760 });
|
||||
await expect.poll(async () => (await preview.boundingBox())!.x > (await tree.boundingBox())!.x).toBe(true);
|
||||
await expect(preview).toContainText("service.find(status");
|
||||
});
|
||||
|
||||
test("⇧F6 renames in place and sends the server's edit to be applied", async ({ workbench: page }) => {
|
||||
const editor = await openSample(page);
|
||||
await page.evaluate(
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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<HTMLDivElement>(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 (
|
||||
<nav
|
||||
className={className}
|
||||
aria-label={ariaLabel}
|
||||
{...props}
|
||||
onKeyDown={(e) => {
|
||||
const buttons = [...e.currentTarget.querySelectorAll<HTMLButtonElement>("button")];
|
||||
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
||||
const buttons = [...(strip.current?.querySelectorAll("button") ?? [])];
|
||||
const index = buttons.indexOf(e.target as HTMLButtonElement);
|
||||
if (index < 0) return;
|
||||
let next: number;
|
||||
@@ -161,7 +186,7 @@ function CrumbNav({ segments, className, ariaLabel }: { segments: Crumb[]; class
|
||||
else if (e.key === "ArrowRight") next = Math.min(buttons.length - 1, index + 1);
|
||||
else if (e.key === "Home") next = 0;
|
||||
else if (e.key === "End") next = buttons.length - 1;
|
||||
else if (e.key === "ArrowDown") {
|
||||
else if (e.key === "ArrowDown" && activateOnDown) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
buttons[index]?.click();
|
||||
@@ -172,30 +197,64 @@ function CrumbNav({ segments, className, ariaLabel }: { segments: Crumb[]; class
|
||||
buttons[next]?.focus();
|
||||
}}
|
||||
>
|
||||
{segments.map((s, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <Icon name="chevron-right" size={12} className={styles.statusSep} />}
|
||||
<BarButton
|
||||
className={styles.crumbButton}
|
||||
tooltip={s.title}
|
||||
aria-haspopup={s.nav ? "listbox" : undefined}
|
||||
onClick={(e) => {
|
||||
const nav = s.nav;
|
||||
const anchor = e.currentTarget;
|
||||
if (nav) setPopup((p) => (p?.anchor === anchor ? null : { nav, anchor }));
|
||||
else s.run?.();
|
||||
}}
|
||||
>
|
||||
{s.icon && <Icon name={s.icon} size={16} className={styles.crumbIcon} />}
|
||||
<span className={styles.crumbLabel}>{s.label}</span>
|
||||
</BarButton>
|
||||
</Fragment>
|
||||
))}
|
||||
{popup && <NavChildrenPopup segment={popup.nav} anchor={popup.anchor} onClose={() => setPopup(null)} />}
|
||||
<div
|
||||
ref={strip}
|
||||
className={styles.crumbStrip}
|
||||
onScroll={(e) => updateBreadcrumbEdges(e.currentTarget)}
|
||||
onWheel={(e) => {
|
||||
if (e.shiftKey || e.ctrlKey || e.deltaX) return;
|
||||
const row = e.currentTarget;
|
||||
const scale = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? row.clientWidth : 1;
|
||||
row.scrollLeft += e.deltaY * scale;
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<BreadcrumbStrip
|
||||
trail={segments.map((s) => 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 (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <Icon name="chevron-right" size={12} className={styles.statusSep} />}
|
||||
<BarButton
|
||||
className={styles.crumbButton}
|
||||
tooltip={s.title}
|
||||
aria-current={current ? "location" : undefined}
|
||||
aria-haspopup={s.nav ? "listbox" : undefined}
|
||||
onClick={(e) => {
|
||||
const nav = s.nav;
|
||||
const anchor = e.currentTarget;
|
||||
if (nav) setPopup((p) => (p?.anchor === anchor ? null : { nav, anchor }));
|
||||
else s.run?.();
|
||||
}}
|
||||
>
|
||||
{icon && (
|
||||
<Icon name={icon} size={s.nav?.kind === "dir" && s.nav.root ? 12 : 16} className={styles.crumbIcon} />
|
||||
)}
|
||||
<span className={styles.crumbLabel}>{s.label}</span>
|
||||
</BarButton>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
{popup && <NavChildrenPopup segment={popup.nav} anchor={popup.anchor} onClose={() => setPopup(null)} />}
|
||||
</BreadcrumbStrip>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <CrumbNav segments={segments} className={className ?? styles.status} ariaLabel={tx("Breadcrumbs")} />;
|
||||
return <CrumbNav segments={segments} className={className ?? styles.status} />;
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<nav
|
||||
<BreadcrumbStrip
|
||||
trail={JSON.stringify([path, fontFamily, fontSize, ...chain.map((item) => item.name)])}
|
||||
style={{ fontFamily, fontSize }}
|
||||
className={clsx(styles.codeCrumbs, position === "top" ? styles.codeCrumbsTop : styles.codeCrumbsBottom)}
|
||||
aria-label={tx("Code breadcrumbs")}
|
||||
>
|
||||
{chain.map((item, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <Icon name="chevron-right" size={12} className={styles.statusSep} />}
|
||||
<BarButton
|
||||
className={styles.crumbButton}
|
||||
tooltip={item.detail ?? item.name}
|
||||
onClick={() =>
|
||||
void editorController().openFile(path, {
|
||||
selection: { line: item.selection_range.start.line, col: item.selection_range.start.col },
|
||||
})
|
||||
}
|
||||
>
|
||||
<Icon name={`symbol-${badgeKind(item.kind)}`} size={14} className={styles.crumbIcon} />
|
||||
<span className={styles.crumbLabel}>{item.name}</span>
|
||||
</BarButton>
|
||||
</Fragment>
|
||||
<BarButton
|
||||
key={i}
|
||||
className={styles.crumbButton}
|
||||
tooltip={item.detail ?? item.name}
|
||||
aria-current={i === chain.length - 1 ? "location" : undefined}
|
||||
onClick={() =>
|
||||
void editorController().openFile(path, {
|
||||
selection: { line: item.selection_range.start.line, col: item.selection_range.start.col },
|
||||
})
|
||||
}
|
||||
>
|
||||
<span className={styles.crumbLabel}>{item.name}</span>
|
||||
</BarButton>
|
||||
))}
|
||||
</nav>
|
||||
</BreadcrumbStrip>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,27 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
height: 26px;
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 0 10px;
|
||||
flex-wrap: wrap;
|
||||
min-height: var(--h-field);
|
||||
gap: var(--space-0-5) var(--space-2);
|
||||
padding: var(--space-0-5) 10px;
|
||||
border-bottom: 1px solid var(--border-popup);
|
||||
font-size: var(--fs-small);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
gap: var(--space-0-5) var(--space-2);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.scope {
|
||||
flex: none;
|
||||
max-width: min(100%, 18em);
|
||||
}
|
||||
|
||||
.searching {
|
||||
@@ -26,23 +35,32 @@
|
||||
}
|
||||
|
||||
.title {
|
||||
flex: 1;
|
||||
flex: 1 1 160px;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
color: var(--fg-emphasis);
|
||||
}
|
||||
.titleLabel {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--fg-emphasis);
|
||||
}
|
||||
.count {
|
||||
flex: none;
|
||||
white-space: nowrap;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.link {
|
||||
flex: none;
|
||||
max-width: 100%;
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--link);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.link:hover {
|
||||
@@ -52,7 +70,6 @@
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 24px;
|
||||
padding: 2px 0;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
@@ -60,21 +77,31 @@
|
||||
flex: 1;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
display: grid;
|
||||
grid-template-columns: min(34%, 176px) 5ch minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.file {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
min-width: 0;
|
||||
}
|
||||
.icon {
|
||||
flex: none;
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
.spacer {
|
||||
flex: 1;
|
||||
.fileName {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.where {
|
||||
flex: none;
|
||||
.line {
|
||||
overflow: hidden;
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: var(--fs-small);
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
@@ -95,12 +122,15 @@
|
||||
outline: none;
|
||||
}
|
||||
.filter {
|
||||
flex: none;
|
||||
max-width: 12ch;
|
||||
font-family: var(--font-mono);
|
||||
color: var(--fg-strong);
|
||||
background: var(--accent-soft);
|
||||
border-radius: var(--radius-small);
|
||||
padding: 0 4px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.noMatch {
|
||||
color: var(--danger);
|
||||
@@ -111,8 +141,9 @@
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.preview {
|
||||
flex: none;
|
||||
height: 200px;
|
||||
flex: 0 1 auto;
|
||||
height: min(164px, 32vh);
|
||||
min-height: min(64px, 18vh);
|
||||
border-top: 1px solid var(--border-popup);
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -131,3 +162,9 @@
|
||||
.previewMatch {
|
||||
background: var(--bg-text-search-result);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.title {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@ function UsagesPopupInner() {
|
||||
const [active, setActive] = useState(0);
|
||||
const current = Math.min(active, items.length - 1);
|
||||
const total = usageCount(groups);
|
||||
const rowCount = Math.max(1, Math.min(14, items.length));
|
||||
const pick = (u: Usage | undefined) => {
|
||||
if (!u) return;
|
||||
close();
|
||||
@@ -158,46 +159,48 @@ function UsagesPopupInner() {
|
||||
>
|
||||
<div className={styles.header}>
|
||||
<span className={styles.title}>
|
||||
{symbol ? tx`Usages of ${symbol}` : tx("Usages")}{" "}
|
||||
<span className={styles.titleLabel}>{symbol ? tx`Usages of ${symbol}` : tx("Usages")}</span>{" "}
|
||||
<span className={styles.count}>
|
||||
{filter || items.length !== total ? tx`${items.length} of ${total} found` : tx`${total} found`}
|
||||
</span>
|
||||
</span>
|
||||
{scope && (
|
||||
<Select<UsageScope>
|
||||
variant="ghost"
|
||||
aria-label={tx("Scope")}
|
||||
className={styles.scope}
|
||||
value={scope}
|
||||
options={[
|
||||
{ value: "project", label: tx("Project Files") },
|
||||
{ value: "libraries", label: tx("Project and Libraries") },
|
||||
]}
|
||||
onChange={setUsagesPopupScope}
|
||||
<div className={styles.actions}>
|
||||
{scope && (
|
||||
<Select<UsageScope>
|
||||
variant="ghost"
|
||||
aria-label={tx("Scope")}
|
||||
className={styles.scope}
|
||||
value={scope}
|
||||
options={[
|
||||
{ value: "project", label: tx("Project Files") },
|
||||
{ value: "libraries", label: tx("Project and Libraries") },
|
||||
]}
|
||||
onChange={setUsagesPopupScope}
|
||||
/>
|
||||
)}
|
||||
{loading && (
|
||||
<span className={styles.searching} role="status" aria-label={tx("Searching for more usages")}>
|
||||
<Spinner size={16} variant="spokes" />
|
||||
</span>
|
||||
)}
|
||||
{filter && (
|
||||
<span className={clsx(styles.filter, !items.length && styles.noMatch)} role="status">
|
||||
{filter}
|
||||
</span>
|
||||
)}
|
||||
<IconButton
|
||||
icon="preview-details"
|
||||
size="small"
|
||||
title="Show Preview"
|
||||
pressed={preview}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => setUsagesPopupPreview(!preview)}
|
||||
/>
|
||||
)}
|
||||
{loading && (
|
||||
<span className={styles.searching} role="status" aria-label={tx("Searching for more usages")}>
|
||||
<Spinner size={16} variant="spokes" />
|
||||
</span>
|
||||
)}
|
||||
{filter && (
|
||||
<span className={clsx(styles.filter, !items.length && styles.noMatch)} role="status">
|
||||
{filter}
|
||||
</span>
|
||||
)}
|
||||
<IconButton
|
||||
icon="preview-details"
|
||||
size="small"
|
||||
title="Show Preview"
|
||||
pressed={preview}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => setUsagesPopupPreview(!preview)}
|
||||
/>
|
||||
<button type="button" className={styles.link} onClick={openInFindWindow}>
|
||||
{tx("Open in Find Window")}
|
||||
{keys ? ` ${keys}` : ""}
|
||||
</button>
|
||||
<button type="button" className={styles.link} onClick={openInFindWindow}>
|
||||
{tx("Open in Find Window")}
|
||||
{keys ? ` ${keys}` : ""}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<UsageAccessFilter items={all} />
|
||||
{note && (
|
||||
@@ -205,7 +208,10 @@ function UsagesPopupInner() {
|
||||
{note}
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.body} style={{ height: Math.max(1, Math.min(14, items.length)) * ROW }}>
|
||||
<div
|
||||
className={styles.body}
|
||||
style={{ height: rowCount * ROW, minHeight: `min(${Math.min(rowCount, 3) * ROW}px, 18vh)` }}
|
||||
>
|
||||
<List
|
||||
items={items}
|
||||
getKey={(u) =>
|
||||
@@ -225,12 +231,14 @@ function UsagesPopupInner() {
|
||||
}
|
||||
renderItem={(u) => (
|
||||
<div className={styles.row} data-testid="usage-row" data-path={u.path} data-line={u.line}>
|
||||
<Icon name={fileIconName(basename(u.path), u.path)} size={16} className={styles.icon} />
|
||||
<UsagePreview usage={u} />
|
||||
<span className={styles.spacer} />
|
||||
<span className={styles.where}>
|
||||
{basename(u.path)}:{u.line + 1}
|
||||
<span className={styles.file}>
|
||||
<Icon name={fileIconName(basename(u.path), u.path)} size={16} className={styles.icon} />
|
||||
<span className={styles.fileName} title={u.path}>
|
||||
{basename(u.path)}
|
||||
</span>
|
||||
</span>
|
||||
<span className={styles.line}>{u.line + 1}</span>
|
||||
<UsagePreview usage={u} />
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
background: var(--border);
|
||||
}
|
||||
.summary {
|
||||
height: 26px;
|
||||
min-height: 26px;
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1-5);
|
||||
padding: 0 10px;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-0-5) var(--space-1-5);
|
||||
padding: var(--space-0-5) 10px;
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg-subtle);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.groupLabel {
|
||||
color: var(--fg);
|
||||
@@ -42,12 +42,13 @@
|
||||
color: var(--danger);
|
||||
}
|
||||
.link {
|
||||
flex: none;
|
||||
max-width: 100%;
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--link);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.link:hover {
|
||||
@@ -81,9 +82,18 @@
|
||||
flex: none;
|
||||
}
|
||||
.file {
|
||||
flex: none;
|
||||
max-width: 56%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--fg);
|
||||
}
|
||||
.muted,
|
||||
.directory {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--fg-subtle);
|
||||
}
|
||||
.count {
|
||||
flex: none;
|
||||
color: var(--fg-subtle);
|
||||
@@ -101,7 +111,7 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-ui);
|
||||
font-size: var(--fs-code);
|
||||
color: var(--fg);
|
||||
}
|
||||
.match {
|
||||
@@ -135,3 +145,18 @@
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
.splitFrame {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
}
|
||||
.sourcePreview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-code);
|
||||
line-height: 1.45;
|
||||
}
|
||||
.sourcePreview .sourceText[role="region"] {
|
||||
font: inherit;
|
||||
font-weight: var(--fw-code);
|
||||
}
|
||||
@@ -2,11 +2,13 @@
|
||||
* "usages" tool window: Find Usages results grouped by file with line
|
||||
* previews, one tab per search (pinnable, as the Find tool window's tabs).
|
||||
*/
|
||||
import { useCallback, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
||||
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
|
||||
import clsx from "clsx";
|
||||
import { create } from "zustand";
|
||||
import { previewColors, tokenSpans, useLineTokens } from "@/editor/lineTokens";
|
||||
import { formatMessage, useTx } from "@/platform/i18n";
|
||||
import { useEditorPrefs } from "@/platform/editorSettings";
|
||||
import { BUNDLED_MONO_FAMILY, monoFontFamily } from "@/platform/fonts";
|
||||
import { shortcutLabel } from "@/platform/keymap";
|
||||
import { basename, relativeDir, useProject } from "@/platform/project";
|
||||
import { maybeEditorService, useOccurrenceNavigator } from "@/workbench/contributions";
|
||||
@@ -245,8 +247,12 @@ export function UsagesView() {
|
||||
return (
|
||||
<span className={clsx(styles.row, isExcluded(n) && styles.excluded)}>
|
||||
<Icon name={fileIconName(basename(path), path)} size={16} className={styles.icon} />
|
||||
<span className={styles.file}>{basename(path)}</span>
|
||||
<span className={styles.muted}>{relativeDir(root, path)}</span>
|
||||
<span className={styles.file} title={path}>
|
||||
{basename(path)}
|
||||
</span>
|
||||
<span className={styles.directory} title={path}>
|
||||
{relativeDir(root, path)}
|
||||
</span>
|
||||
<span className={styles.count}>
|
||||
{n.group.usages.length} {tx(n.group.usages.length === 1 ? "usage" : "usages")}
|
||||
</span>
|
||||
@@ -401,34 +407,62 @@ export function useUsagesHeaderMenu(): MenuItem[] {
|
||||
|
||||
function UsagesSplit({ preview, children }: { preview: ReactNode; children: ReactNode }) {
|
||||
const show = useUsagesOptions((s) => s.preview);
|
||||
const frame = useRef<HTMLDivElement>(null);
|
||||
const [stacked, setStacked] = useState(false);
|
||||
useLayoutEffect(() => {
|
||||
const el = frame.current;
|
||||
if (!show || !el) return;
|
||||
const measure = () => setStacked(el.clientWidth < 580);
|
||||
measure();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
}, [show]);
|
||||
if (!show) return children;
|
||||
return (
|
||||
<SplitGroup orientation="horizontal" id="usages-preview-split" storageKey="openidea.usages.previewSplit">
|
||||
<SplitPanel id="usages" minSize={160} className={styles.panel}>
|
||||
{children}
|
||||
</SplitPanel>
|
||||
<SplitHandle />
|
||||
<SplitPanel id="preview" minSize={160} defaultSize="45%" className={styles.panel}>
|
||||
{preview}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
<div ref={frame} className={styles.splitFrame}>
|
||||
<SplitGroup
|
||||
orientation={stacked ? "vertical" : "horizontal"}
|
||||
id="usages-preview-split"
|
||||
storageKey={stacked ? "openidea.usages.previewSplit.vertical" : "openidea.usages.previewSplit"}
|
||||
>
|
||||
<SplitPanel id="usages" minSize={stacked ? "30%" : 160} className={styles.panel}>
|
||||
{children}
|
||||
</SplitPanel>
|
||||
<SplitHandle />
|
||||
<SplitPanel id="preview" minSize={stacked ? "30%" : 160} defaultSize="45%" className={styles.panel}>
|
||||
{preview}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UsagesPreview({ node }: { node: Node | null }) {
|
||||
const usage = node?.kind === "usage" ? node.usage : node?.kind === "file" ? (node.group.usages[0] ?? null) : null;
|
||||
const search = useUsages(activeUsageSearch);
|
||||
const settings = useProject((s) => s.settings?.editor);
|
||||
const { fallbackFont } = useEditorPrefs();
|
||||
const family = settings?.fontFamily;
|
||||
const fontFamily =
|
||||
(family && family !== BUNDLED_MONO_FAMILY) || fallbackFont.trim()
|
||||
? monoFontFamily(family, fallbackFont, "var(--font-mono)")
|
||||
: undefined;
|
||||
const highlights = useMemo(() => {
|
||||
const group = usage && search?.groups.find((g) => g.path === usage.path);
|
||||
return (group?.usages ?? []).map((u) => ({ line: u.line, ranges: [[u.col, u.endCol] as const] }));
|
||||
}, [usage, search?.groups]);
|
||||
return (
|
||||
<SourcePreview
|
||||
path={usage?.path ?? null}
|
||||
line={usage?.line ?? 0}
|
||||
highlights={highlights}
|
||||
load={previewText}
|
||||
colorize={previewColors}
|
||||
/>
|
||||
<div className={styles.sourcePreview} style={{ fontFamily, fontSize: settings?.fontSize ?? undefined }}>
|
||||
<SourcePreview
|
||||
path={usage?.path ?? null}
|
||||
line={usage?.line ?? 0}
|
||||
highlights={highlights}
|
||||
load={previewText}
|
||||
colorize={previewColors}
|
||||
className={styles.sourceText}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -112,22 +112,24 @@ export function StatusBar({ lightEdit = false }: { lightEdit?: boolean }) {
|
||||
return () => ro.disconnect();
|
||||
}, []);
|
||||
useLayoutEffect(() => {
|
||||
const leftHosts = [...(barRef.current?.querySelectorAll<HTMLElement>(":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<HTMLElement>(":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) => {
|
||||
|
||||
Reference in new issue
Заблокувати користувача