mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(navigation): align the Select In chooser (#4909)
fix(navigation): align the Select In chooser
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { expect, test } from "./fixtures";
|
||||
|
||||
test("Select In names the chooser and reveals the file in the requested project view", async ({ workbench: page }) => {
|
||||
const tree = page.getByRole("tree", { name: "Project", exact: true });
|
||||
await tree.getByRole("treeitem", { name: "settings.gradle.kts", exact: true }).dblclick();
|
||||
await expect(page.locator(".cm-content")).toBeVisible();
|
||||
|
||||
const openChooser = () =>
|
||||
page.evaluate(async () => {
|
||||
const actions = "/src/platform/actions.ts";
|
||||
await (await import(/* @vite-ignore */ actions)).executeAction("navigate.selectIn");
|
||||
});
|
||||
await openChooser();
|
||||
const menu = page.getByRole("menu", { name: "Select In", exact: true });
|
||||
await expect(menu.getByText("Select In", { exact: true })).toBeVisible();
|
||||
const project = menu.getByRole("menuitem", { name: "Project View", exact: true });
|
||||
await expect(project).toBeFocused();
|
||||
await expect(project.locator('[data-menu-number="1"]')).toBeVisible();
|
||||
|
||||
await page.keyboard.press("ArrowRight");
|
||||
const projectFiles = page.getByRole("menuitem", { name: "Project Files", exact: true });
|
||||
await expect(project).toHaveAttribute("aria-expanded", "true");
|
||||
await expect(projectFiles).toBeVisible();
|
||||
await expect(page.getByRole("menuitem", { name: "Open Files", exact: true })).toBeEnabled();
|
||||
await expect(page.getByRole("menuitem", { name: "All Changed Files", exact: true })).toBeDisabled();
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect(projectFiles).toBeHidden();
|
||||
await expect(project).toBeFocused();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await expect(projectFiles).toBeFocused();
|
||||
await page.keyboard.press("Enter");
|
||||
|
||||
await expect(menu).toBeHidden();
|
||||
await expect(page.getByRole("button", { name: "Project Files", exact: true })).toBeVisible();
|
||||
const file = tree.getByRole("treeitem", { name: "settings.gradle.kts", exact: true });
|
||||
await expect(file).toHaveAttribute("aria-selected", "true");
|
||||
|
||||
await page.locator(".cm-content").focus();
|
||||
await openChooser();
|
||||
await expect(project).toBeFocused();
|
||||
await project.locator("[data-menu-submenu-arrow]").click();
|
||||
await expect(projectFiles).toBeVisible();
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await expect(project).toBeFocused();
|
||||
await page.keyboard.press("1");
|
||||
await expect(menu).toBeHidden();
|
||||
await expect(page.getByRole("button", { name: "Project Files", exact: true })).toBeVisible();
|
||||
await expect(file).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
@@ -119,9 +119,24 @@ export function selectInProjectView(path?: string | null, focus = true) {
|
||||
* menu groups), the navigation bar, Finder / Explorer and the terminal.
|
||||
*/
|
||||
export function selectInTargets(path: string): MenuItem[] {
|
||||
const { unity } = useProjectTree.getState();
|
||||
const views = VIEW_MODES.filter(([mode]) => mode !== "unity" || unity).map(([mode, label]) => ({
|
||||
label,
|
||||
disabled: !modeShows(path, mode),
|
||||
run: () => {
|
||||
setViewMode(mode);
|
||||
selectInProjectView(path);
|
||||
},
|
||||
}));
|
||||
return [
|
||||
{ kind: "header", label: "Select In" },
|
||||
{ label: "Project View", icon: "toolwindow-project", run: () => void selectInProjectView(path) },
|
||||
{ kind: "header", label: "Select In", asTitle: true },
|
||||
{
|
||||
label: "Project View",
|
||||
icon: "toolwindow-project",
|
||||
run: () => void selectInProjectView(path),
|
||||
submenu: views,
|
||||
performOnSelect: true,
|
||||
},
|
||||
...menuGroupItems("selectIn", { paths: [path] }),
|
||||
...(getAction("navigate.navigationBar") && maybeEditorService()?.activePath() === path
|
||||
? [{ kind: "action" as const, action: "navigate.navigationBar", label: "Navigation Bar" }]
|
||||
@@ -153,7 +168,6 @@ export function showNewPopupForEditor(orRoot = false): boolean {
|
||||
}
|
||||
|
||||
function showSelectIn(path: string) {
|
||||
// At the caret, like IDEA's popup; centred near the top otherwise.
|
||||
const view = activeEditor()?.view;
|
||||
const coords = view && activeEditor()?.ctx.path === path ? view.coordsAtPos(view.state.selection.main.head) : null;
|
||||
const at = coords ? { x: coords.left, y: coords.bottom + 2 } : { x: window.innerWidth / 2 - 100, y: 80 };
|
||||
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
type ProjectViewLead,
|
||||
type ProjectViewRootContribution,
|
||||
} from "@/workbench/contributions";
|
||||
import { ancestorsWithin, isSameOrInside, nameOf, type PackageKind } from "./paths";
|
||||
import { ancestorsWithin, isInside, isSameOrInside, nameOf, type PackageKind } from "./paths";
|
||||
|
||||
export interface ViewOptions extends TreeOptions {
|
||||
/** Select the active editor's file in the tree (IDEA: Always Select Opened File). */
|
||||
@@ -730,23 +730,29 @@ export function extraRootOf(path: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Whether the current pane can show `path` (Select In switches to "Project" otherwise). */
|
||||
export function modeShows(path: string): boolean {
|
||||
const { mode, root } = get();
|
||||
if (!root) return false;
|
||||
/** Whether a pane can show `path`. */
|
||||
export function modeShows(path: string, mode = get().mode): boolean {
|
||||
const state = get();
|
||||
if (!state.root) return false;
|
||||
switch (mode) {
|
||||
case "unity":
|
||||
return unityPathVisible(path, treeOptions(get()));
|
||||
return !!state.unity && unityPathVisible(path, treeOptions({ ...state, mode }));
|
||||
case "project":
|
||||
return true;
|
||||
case "projectFiles":
|
||||
return memberRootOf(path) !== null || (!get().members && isSameOrInside(path, root));
|
||||
return memberRootOf(path) !== null || (!state.members && isSameOrInside(path, state.root));
|
||||
case "scratches":
|
||||
return projectViewRoots(useProjectViewRoots.getState().roots).some(
|
||||
(r) => r.scope === "scratches" && r.path !== undefined && isSameOrInside(path, r.path),
|
||||
);
|
||||
default:
|
||||
return currentModel().keyOfPath.has(path);
|
||||
default: {
|
||||
if (mode === state.mode) return currentModel().keyOfPath.has(path);
|
||||
const pane = { ...state, mode };
|
||||
const files = filesOf(pane);
|
||||
if (files?.includes(path)) return true;
|
||||
// Only a folder that contains a listed file needs a tree lookup.
|
||||
return !!files?.some((file) => isInside(file, path)) && selectModel(pane).keyOfPath.has(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,15 @@
|
||||
color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: var(--h-list-row);
|
||||
margin-bottom: var(--space-1);
|
||||
padding-inline: var(--space-3);
|
||||
color: var(--fg-strong);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Settings › Appearance › "Display icons in menu items" off: keep the column, drop the icon. */
|
||||
:global(:root[data-menu-icons="off"]) .icon[data-menu-icon] > * {
|
||||
|
||||
+17
-10
@@ -25,7 +25,7 @@ import { isSubmenuAim, type MenuPointer } from "./menuAim";
|
||||
|
||||
export type MenuItem =
|
||||
| { kind: "separator" }
|
||||
| { kind: "header"; label: string }
|
||||
| { kind: "header"; label: string; asTitle?: boolean }
|
||||
| {
|
||||
kind: "action";
|
||||
action: string;
|
||||
@@ -56,12 +56,14 @@ export type MenuItem =
|
||||
/** The pointer or the keyboard made it the active item (not on opening the menu). */
|
||||
onActive?: () => void;
|
||||
submenu?: MenuItem[];
|
||||
/** Run the item when activated. Hover, Right Arrow and the chevron open its submenu. */
|
||||
performOnSelect?: boolean;
|
||||
/** The text the item copies, for choosers that show it (Copy Path/Reference…). */
|
||||
preview?: string;
|
||||
};
|
||||
|
||||
interface Resolved {
|
||||
kind: "item" | "separator" | "header";
|
||||
kind: "item" | "separator" | "header" | "title";
|
||||
key: string;
|
||||
label: string;
|
||||
icon?: string;
|
||||
@@ -75,6 +77,7 @@ interface Resolved {
|
||||
hint?: string;
|
||||
onActive?: () => void;
|
||||
submenu?: MenuItem[];
|
||||
performOnSelect?: boolean;
|
||||
}
|
||||
|
||||
export function resolveMenuItems(items: MenuItem[]): Resolved[] {
|
||||
@@ -86,7 +89,7 @@ export function resolveMenuItems(items: MenuItem[]): Resolved[] {
|
||||
return;
|
||||
}
|
||||
if (item.kind === "header") {
|
||||
out.push({ kind: "header", key: `h${i}`, label: tx(item.label) });
|
||||
out.push({ kind: item.asTitle ? "title" : "header", key: `h${i}`, label: tx(item.label) });
|
||||
return;
|
||||
}
|
||||
if (item.kind === "action") {
|
||||
@@ -157,6 +160,7 @@ export function MenuList({
|
||||
// (e.g. editorTextFocus → popupOpen) right after the first render.
|
||||
useContextKeys();
|
||||
const resolved = resolveMenuItems(items);
|
||||
const title = resolved.find((item) => item.kind === "title")?.label;
|
||||
const hasSubmenus = resolved.some((item) => item.submenu);
|
||||
// IDEA numeric mnemonics: the first nine selectable rows, in display order.
|
||||
const numbersOf: Array<number | undefined> = [];
|
||||
@@ -213,11 +217,11 @@ export function MenuList({
|
||||
}
|
||||
};
|
||||
|
||||
const activate = (i: number, modifiers?: Pick<KeyboardEvent, "metaKey" | "ctrlKey">) => {
|
||||
const activate = (i: number, modifiers?: Pick<KeyboardEvent, "metaKey" | "ctrlKey">, openChild = false) => {
|
||||
cancelHover();
|
||||
const item = resolved[i];
|
||||
if (!selectable(item)) return;
|
||||
if (item!.submenu) {
|
||||
if (item!.submenu && (openChild || !item!.performOnSelect)) {
|
||||
setActive(i);
|
||||
setOpenSub(i);
|
||||
return;
|
||||
@@ -363,7 +367,7 @@ export function MenuList({
|
||||
return (
|
||||
<div
|
||||
role="menu"
|
||||
aria-label={aria["aria-label"]}
|
||||
aria-label={title ?? aria["aria-label"]}
|
||||
className={styles.menu}
|
||||
onKeyDown={onKeyDown}
|
||||
// A right-click in an open menu does nothing; without this it reaches whatever is under the
|
||||
@@ -375,9 +379,9 @@ export function MenuList({
|
||||
>
|
||||
{resolved.map((r, i) => {
|
||||
if (r.kind === "separator") return <div key={r.key} role="separator" className={styles.separator} />;
|
||||
if (r.kind === "header")
|
||||
if (r.kind === "header" || r.kind === "title")
|
||||
return (
|
||||
<div key={r.key} role="presentation" className={styles.header}>
|
||||
<div key={r.key} role="presentation" className={r.kind === "title" ? styles.title : styles.header}>
|
||||
{r.label}
|
||||
</div>
|
||||
);
|
||||
@@ -406,7 +410,10 @@ export function MenuList({
|
||||
onMouseEnter={(e) => hover(i, { x: e.clientX, y: e.clientY })}
|
||||
onPointerLeave={() => leave(i)}
|
||||
onMouseLeave={() => leave(i)}
|
||||
onClick={(e) => activate(i, e)}
|
||||
onClick={(e) => {
|
||||
const openChild = e.target instanceof Element && e.target.closest("[data-menu-submenu-arrow]") !== null;
|
||||
activate(i, e, openChild);
|
||||
}}
|
||||
title={r.hint}
|
||||
>
|
||||
{numbers && (
|
||||
@@ -428,7 +435,7 @@ export function MenuList({
|
||||
</span>
|
||||
)}
|
||||
{hasSubmenus && (
|
||||
<span className={styles.subArrow} aria-hidden="true">
|
||||
<span className={styles.subArrow} aria-hidden="true" data-menu-submenu-arrow={hasSub || undefined}>
|
||||
{hasSub && <Icon name="chevron-right" size={14} />}
|
||||
</span>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user