Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 7421fef185 feat(run): fold the chooser's other configurations under All Configurations
Once some configurations are pinned or recent (and there are five or more),
the run configuration chooser folds the rest under a collapsed
"All Configurations N" row; expanded, it lists every configuration by type,
and the state is kept per project. A search still finds the folded ones.

Each row gets a ⋮ button (also → on the keyboard) that opens its actions:
Run, Debug, Edit…, Pin / Unpin and Delete. Pin moves from the row into this
menu. Current File now follows the configurations, before Edit
Configurations…, with separators between them.

Closes #3074
2026-11-15 10:34:27 +08:00
7 змінених файлів з 292 додано та 62 видалено

No files matched your search

+139 -52
Переглянути файл
@@ -2,7 +2,20 @@ import { useEffect, useMemo, useState, type KeyboardEvent } from "react";
import clsx from "clsx";
import { executeAction } from "@/platform/actions";
import { shortcutLabel } from "@/platform/keymap";
import { HighlightedText, Icon, IconButton, List, Popup, SearchField, fuzzyMatch, listNavigate, T } from "@/ui";
import {
HighlightedText,
Icon,
IconButton,
List,
Menu,
Popup,
SearchField,
firstSelectable,
fuzzyMatch,
listNavigate,
T,
type MenuItem,
} from "@/ui";
import type { RunConfig } from "@/platform/ipc";
import { useWorkflowSettings } from "@/platform/workflowSettings";
import { useDebugRunSessions } from "@/workbench/contributions";
@@ -12,9 +25,11 @@ import {
canDeleteConfig,
CURRENT_FILE,
deleteConfig,
MAX_RECENT,
saveTemporary,
selectConfig,
startRun,
toggleAllConfigurations,
togglePinned,
useRun,
} from "./store";
@@ -23,13 +38,16 @@ import styles from "./Run.module.css";
import { tx } from "@/platform/i18n";
type Row =
/** A labelled group, or a thin separator when `label` is empty. */
| { type: "section"; key: string; label: string }
| { type: "config"; key: string; config: RunConfig; indices: number[] | null }
| { type: "all"; key: string; count: number; expanded: boolean }
| { type: "edit"; key: string }
| { type: "current"; key: string; indices: number[] | null }
| { type: "save"; key: string; config: RunConfig };
const ROW = 24;
const SEPARATOR = 9;
const CURRENT_FILE_LABEL = "Current File";
export function buildRows(
@@ -39,40 +57,49 @@ export function buildRows(
temporary: readonly string[] = [],
pinned: readonly string[] = [],
recent: readonly string[] = [],
allExpanded = false,
): Row[] {
const rows: Row[] = [];
// IDEA: "Save '<name>' Configuration" first while a temporary configuration is selected.
if (!query && selected && temporary.includes(selected.id)) rows.push({ type: "save", key: "save", config: selected });
// IDEA: the permanent "Current File" entry runs the active file's context.
const currentIndices = query ? fuzzyMatch(CURRENT_FILE_LABEL, query) : null;
if (!query || currentIndices) rows.push({ type: "current", key: "current", indices: currentIndices });
const matching = (list: readonly RunConfig[]) =>
list.map((c) => ({ c, indices: query ? fuzzyMatch(c.name, query) : null })).filter((x) => !query || x.indices);
const pushGroup = (label: string, key: string, list: readonly RunConfig[], prefix = "c") => {
const matched = matching(list);
if (matched.length === 0) return;
rows.push({ type: "section", key, label });
for (const { c, indices } of matched) rows.push({ type: "config", key: `${prefix}:${c.id}`, config: c, indices });
};
// IDEA: pinned configurations come first, in the order they were pinned.
const pinnedConfigs = pinned.flatMap((id) => configs.find((c) => c.id === id) ?? []);
const pinnedRows = matching(pinnedConfigs);
if (pinnedRows.length) {
rows.push({ type: "section", key: "s:pinned", label: tx("Pinned") });
for (const { c, indices } of pinnedRows) rows.push({ type: "config", key: `c:${c.id}`, config: c, indices });
}
pushGroup(tx("Pinned"), "s:pinned", pinnedConfigs);
// Then the ones started last, newest first.
const recentConfigs = recent.flatMap((id) => configs.find((c) => c.id === id && !pinned.includes(id)) ?? []);
const recentRows = matching(recentConfigs);
if (recentRows.length) {
rows.push({ type: "section", key: "s:recent", label: tx("Recent") });
for (const { c, indices } of recentRows) rows.push({ type: "config", key: `c:${c.id}`, config: c, indices });
}
pushGroup(tx("Recent"), "s:recent", recentConfigs);
const rest = configs.filter((c) => !pinnedConfigs.includes(c) && !recentConfigs.includes(c));
for (const group of groupConfigs(rest)) {
const matched = matching(group.configs);
if (matched.length === 0) continue;
rows.push({ type: "section", key: `s:${group.kind}`, label: group.label });
for (const { c, indices } of matched) rows.push({ type: "config", key: `c:${c.id}`, config: c, indices });
// IDEA: once there are pinned or recent configurations, the others fold under "All Configurations"
// (collapsed by default). Expanded, it lists every configuration by type; a search finds the folded ones.
const folded = (pinnedConfigs.length > 0 || recentConfigs.length > 0) && configs.length >= MAX_RECENT;
if (folded && !query) {
rows.push({ type: "all", key: "all", count: configs.length, expanded: allExpanded });
if (allExpanded)
for (const group of groupConfigs(configs)) pushGroup(group.label, `a:${group.kind}`, group.configs, "a");
} else {
for (const group of groupConfigs(rest)) pushGroup(group.label, `s:${group.kind}`, group.configs);
}
// IDEA: the permanent "Current File" entry (runs the active file's context) follows the configurations.
const currentIndices = query ? fuzzyMatch(CURRENT_FILE_LABEL, query) : null;
if (!query || currentIndices) {
if (rows.length) rows.push({ type: "section", key: "sep:current", label: "" });
rows.push({ type: "current", key: "current", indices: currentIndices });
}
if (rows.length) rows.push({ type: "section", key: "sep:edit", label: "" });
rows.push({ type: "edit", key: "edit" });
return rows;
}
const rowHeight = (r: Row) => (r.type === "section" && !r.label ? SEPARATOR : ROW);
let closedAt = 0;
/** The chooser closed within the last moment (a click on its own anchor shouldn't reopen it). */
export function chooserJustClosed(): boolean {
@@ -90,10 +117,14 @@ export function ConfigChooserOverlay() {
return <ConfigChooser />;
}
/** Numeric mnemonics (IDEA: 1–9 run the Nth configuration while the search is empty). */
/**
* Numeric mnemonics (IDEA: 1–9 run the Nth configuration while the search is empty), for the
* configurations above "All Configurations".
*/
export function mnemonics(rows: readonly Row[]): Map<string, number> {
const out = new Map<string, number>();
for (const r of rows) {
if (r.type === "all") break;
if (r.type !== "config") continue;
if (out.size >= 9) break;
out.set(r.key, out.size + 1);
@@ -108,6 +139,7 @@ function ConfigChooser() {
const temporary = useRun((s) => s.temporary);
const pinned = useRun((s) => s.pinned);
const recent = useRun((s) => s.recent);
const allExpanded = useRun((s) => s.allExpanded);
const runTargets = useWorkflowSettings((s) => s.runTargets);
const sessions = useRun((s) => s.sessions);
const debugSessions = useDebugRunSessions((s) => s.sessions);
@@ -121,24 +153,26 @@ function ConfigChooser() {
temporary,
pinned,
recent,
allExpanded,
),
[configs, query, selectedId, temporary, pinned, recent],
[configs, query, selectedId, temporary, pinned, recent, allExpanded],
);
const isSection = (r: Row) => r.type === "section";
const initial = Math.max(
0,
const [active, setActive] = useState(() =>
rows.findIndex(
(r) =>
(r.type === "config" && r.config.id === selectedId) || (r.type === "current" && selectedId === CURRENT_FILE),
),
);
const [active, setActive] = useState(initial);
// The configuration whose actions menu (⋮) is open.
const [menu, setMenu] = useState<{ name: string; anchor: Element; items: MenuItem[] } | null>(null);
const [anchor] = useState(anchorElement);
const close = () => {
closedAt = Date.now();
useRun.setState({ chooserOpen: false });
};
const clamped = Math.min(active, rows.length - 1);
// Negative: the first row that can be selected (on opening without a visible selection, after a search).
const clamped = active < 0 ? firstSelectable(rows, isSection) : Math.min(active, rows.length - 1);
const numbers = useMemo(
() => (mode === "select" || query ? new Map<string, number>() : mnemonics(rows)),
[mode, query, rows],
@@ -161,6 +195,10 @@ function ConfigChooser() {
const activate = (row: Row | undefined, how: "select" | "run" | "debug" | "edit" = executor) => {
if (!row) return;
if (row.type === "all") {
toggleAllConfigurations();
return;
}
close();
if (row.type === "edit") {
void executeAction("run.editConfigs");
@@ -187,23 +225,32 @@ function ConfigChooser() {
const onKeyDown = (e: KeyboardEvent) => {
const row = rows[clamped];
const input = () => e.target as HTMLInputElement;
if (e.key === "Enter") {
e.preventDefault();
// The widget (select mode) keeps Shift+Enter = Debug and Alt/⌘+Enter = Run.
activate(row, mode !== "select" ? executor : e.shiftKey ? "debug" : e.altKey || e.metaKey ? "run" : "select");
return;
}
// IDEA: → opens the configuration's actions, as its ⋮ button does.
if (e.key === "ArrowRight" && row?.type === "config" && input().selectionStart === query.length) {
const anchor = document.querySelector("[data-chooser-more]")?.closest("[role='option']");
if (anchor) {
e.preventDefault();
openMenu(row.config, anchor);
return;
}
}
if (e.key === "F4" && row?.type === "config") {
e.preventDefault();
activate(row, "edit");
return;
}
const input = e.target as HTMLInputElement;
if (
e.key === "Delete" &&
row?.type === "config" &&
canDeleteConfig(row.config.id) &&
input.selectionStart === query.length
input().selectionStart === query.length
) {
e.preventDefault();
void deleteConfig(row.config.id);
@@ -225,7 +272,39 @@ function ConfigChooser() {
}
};
const height = Math.min(rows.length * ROW, 14 * ROW);
const height = Math.min(
rows.reduce((sum, r) => sum + rowHeight(r), 0),
14 * ROW,
);
// IDEA: a configuration's submenu lists its executors, then Edit and Pin.
const menuItems = (c: RunConfig): MenuItem[] => {
const row: Row = { type: "config", key: `c:${c.id}`, config: c, indices: null };
return [
{ label: "Run", icon: "run", run: () => activate(row, "run") },
{ label: "Debug", icon: "debug", run: () => activate(row, "debug") },
{ kind: "header", label: "Configuration" },
{ label: "Edit…", icon: "edit", run: () => activate(row, "edit") },
{ label: pinned.includes(c.id) ? "Unpin" : "Pin", icon: "pin", run: () => togglePinned(c.id) },
...(canDeleteConfig(c.id) ? [{ label: "Delete", danger: true, run: () => void deleteConfig(c.id) }] : []),
];
};
const openMenu = (c: RunConfig, at: Element) => setMenu({ name: c.name, anchor: at, items: menuItems(c) });
const more = (c: RunConfig) => (
<IconButton
icon="more"
size="small"
iconSize={13}
title={tx("More Actions")}
data-chooser-more=""
tabIndex={-1}
onClick={(e) => {
e.stopPropagation();
// On the row, like IDEA's submenus: the button goes away when the pointer leaves the row.
openMenu(c, e.currentTarget.closest("[role='option']") ?? e.currentTarget);
}}
/>
);
return (
<Popup
@@ -247,7 +326,7 @@ function ConfigChooser() {
value={query}
onChange={(v) => {
setQuery(v);
setActive(1);
setActive(-1);
}}
placeholder="Search configurations"
aria-label="Search configurations"
@@ -263,7 +342,14 @@ function ConfigChooser() {
items={rows}
getKey={(r) => r.key}
isSection={isSection}
renderSection={(r) => (r.type === "section" ? <T>{r.label}</T> : null)}
sectionHeightOf={(r) => (r.type === "section" && !r.label ? SEPARATOR : undefined)}
renderSection={(r) =>
r.type === "section" && r.label ? (
<T>{r.label}</T>
) : (
<span className={styles.chooserSeparator} role="separator" />
)
}
activeIndex={clamped}
onActiveChange={setActive}
focusable={false}
@@ -293,6 +379,17 @@ function ConfigChooser() {
</span>
);
}
if (r.type === "all") {
return (
<span className={clsx(styles.chooserRow, styles.chooserEdit)} aria-expanded={r.expanded}>
<Icon name={r.expanded ? "chevron-down" : "chevron-right"} size={13} />
<span className={styles.chooserName}>
<T>All Configurations</T>
<span className={styles.chooserCount}>{r.count}</span>
</span>
</span>
);
}
if (r.type === "edit") {
return (
<span className={clsx(styles.chooserRow, styles.chooserEdit)}>
@@ -338,17 +435,6 @@ function ConfigChooser() {
)}
{isActive && running && (
<span className={styles.chooserActions}>
<IconButton
icon="pin"
size="small"
iconSize={12}
title={pinned.includes(c.id) ? tx("Unpin") : tx("Pin")}
tabIndex={-1}
onClick={(e) => {
e.stopPropagation();
togglePinned(c.id);
}}
/>
<IconButton
icon={running.debug ? "restart-debug-filled" : "rerun-filled"}
size="small"
@@ -373,21 +459,11 @@ function ConfigChooser() {
running.stop();
}}
/>
{more(c)}
</span>
)}
{isActive && !running && (
<span className={styles.chooserActions}>
<IconButton
icon="pin"
size="small"
iconSize={12}
title={pinned.includes(c.id) ? tx("Unpin") : tx("Pin")}
tabIndex={-1}
onClick={(e) => {
e.stopPropagation();
togglePinned(c.id);
}}
/>
<IconButton
icon="run"
size="small"
@@ -410,6 +486,7 @@ function ConfigChooser() {
activate(r, "debug");
}}
/>
{more(c)}
</span>
)}
</span>
@@ -426,6 +503,16 @@ function ConfigChooser() {
</T>
</div>
)}
{menu && (
<Menu
open
anchor={menu.anchor}
placement="right-start"
items={menu.items}
onClose={() => setMenu(null)}
aria-label={tx`Actions for ${menu.name}`}
/>
)}
</Popup>
);
}
+11
Переглянути файл
@@ -479,6 +479,17 @@
display: flex;
margin-right: -4px;
}
.chooserSeparator {
flex: 1;
height: 1px;
margin: 0 4px;
background: var(--border-popup);
}
/* IDEA: the number of configurations after "All Configurations". */
.chooserCount {
margin-left: 6px;
color: var(--fg-faint);
}
.badge {
flex: none;
padding: 0 5px;
+109 -7
Переглянути файл
@@ -39,20 +39,32 @@ afterEach(() => {
});
const names = (rows: ReturnType<typeof buildRows>) =>
rows.map((r) => (r.type === "section" ? `[${r.label}]` : r.type === "config" ? r.config.name : r.type));
rows.map((r) =>
r.type === "section"
? r.label
? `[${r.label}]`
: "---"
: r.type === "config"
? r.config.name
: r.type === "all"
? `all ${r.count}${r.expanded ? " v" : " >"}`
: r.type,
);
it("lists pinned configurations first, in pin order, and not again in their group", () => {
expect(names(buildRows(configs, "", null, [], ["serve", "App", "gone"]))).toEqual([
"current",
"[Pinned]",
"serve",
"App",
"[npm]",
"build",
"---",
"current",
"---",
"edit",
]);
// A search keeps the pinned matches on top.
expect(names(buildRows(configs, "s", null, [], ["serve"]))).toEqual(["[Pinned]", "serve", "edit"]);
expect(names(buildRows(configs, "s", null, [], ["serve"]))).toEqual(["[Pinned]", "serve", "---", "edit"]);
});
it("keeps pins per project across reloads", async () => {
@@ -70,27 +82,117 @@ it("keeps pins per project across reloads", async () => {
expect(useRun.getState().pinned).toEqual([]);
});
it("pins and unpins from the row's button", async () => {
it("pins and unpins from the row's actions menu", async () => {
await loadConfigs();
useRun.setState({ chooserOpen: true });
render(<ConfigChooserOverlay />);
fireEvent.pointerMove(screen.getByRole("option", { name: /^build/ }));
fireEvent.click(screen.getByRole("button", { name: "Pin" }));
fireEvent.click(screen.getByRole("button", { name: "More Actions" }));
fireEvent.click(screen.getByRole("menuitem", { name: "Pin" }));
expect(useRun.getState().pinned).toEqual(["build"]);
expect(useRun.getState().chooserOpen).toBe(true);
expect(screen.getByText("Pinned")).toBeInTheDocument();
fireEvent.pointerMove(screen.getByRole("option", { name: /^build/ }));
fireEvent.click(screen.getByRole("button", { name: "Unpin" }));
fireEvent.click(screen.getByRole("button", { name: "More Actions" }));
fireEvent.click(screen.getByRole("menuitem", { name: "Unpin" }));
expect(useRun.getState().pinned).toEqual([]);
});
it("offers the configuration's executors, Edit and Delete in its actions menu, also on →", async () => {
await loadConfigs();
useRun.setState({ chooserOpen: true });
render(<ConfigChooserOverlay />);
fireEvent.pointerMove(screen.getByRole("option", { name: /^serve/ }));
fireEvent.keyDown(screen.getByLabelText("Search configurations"), { key: "ArrowRight" });
const items = screen.getAllByRole("menuitem").map((el) => el.textContent);
expect(items).toEqual(["Run", "Debug", "Edit…", "Pin", "Delete"]);
fireEvent.click(screen.getByRole("menuitem", { name: "Edit…" }));
expect(useRun.getState().chooserOpen).toBe(false);
expect(useRun.getState().selectedId).toBe("serve");
});
const many = ["a", "b", "c", "d", "e", "f"].map((id) => config(id));
it("folds the other configurations under All Configurations once some are pinned or recent", () => {
// Fewer than five configurations: no folding.
expect(names(buildRows(configs, "", null, [], [], ["serve"]))).toEqual([
"[Recent]",
"serve",
"[npm]",
"build",
"[Application]",
"App",
"---",
"current",
"---",
"edit",
]);
// Nothing pinned or recent: everything stays listed.
expect(names(buildRows(many, ""))[0]).toBe("[npm]");
expect(names(buildRows(many, "", null, [], ["b"], ["d"]))).toEqual([
"[Pinned]",
"b",
"[Recent]",
"d",
"all 6 >",
"---",
"current",
"---",
"edit",
]);
// Expanded, it lists every configuration by type, the pinned and recent ones included.
expect(names(buildRows(many, "", null, [], ["b"], ["d"], true))).toEqual([
"[Pinned]",
"b",
"[Recent]",
"d",
"all 6 v",
"[npm]",
"a",
"b",
"c",
"d",
"e",
"f",
"---",
"current",
"---",
"edit",
]);
// A search finds the folded ones, once each.
expect(names(buildRows(many, "e", null, [], ["b"], ["d"]))).toEqual(["[npm]", "e", "---", "current", "---", "edit"]);
});
it("expands All Configurations in place and remembers it per project", async () => {
ipc.runConfigs.mockImplementation(async () => ({ status: "ok", data: many }));
await loadConfigs();
togglePinned("a");
useRun.setState({ chooserOpen: true });
render(<ConfigChooserOverlay />);
expect(screen.queryByRole("option", { name: /^c/ })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("option", { name: /^All Configurations/ }));
expect(useRun.getState().chooserOpen).toBe(true);
expect(screen.getByRole("option", { name: /^c/ })).toBeInTheDocument();
cleanup();
resetRuns();
await loadConfigs();
expect(useRun.getState().allExpanded).toBe(true);
useProject.setState({ project: { root: "/other" } as never });
resetRuns();
await loadConfigs();
expect(useRun.getState().allExpanded).toBe(false);
});
it("lists the configurations started last after the pinned ones, newest first", () => {
expect(names(buildRows(configs, "", null, [], ["serve"], ["App", "serve", "build"]))).toEqual([
"current",
"[Pinned]",
"serve",
"[Recent]",
"App",
"build",
"---",
"current",
"---",
"edit",
]);
});
+1 -1
Переглянути файл
@@ -893,7 +893,7 @@ describe("debug-only types (Remote JVM Debug)", () => {
describe("Current File", () => {
it("is always offered in the chooser", () => {
expect(buildRows([], "")[0]).toMatchObject({ type: "current" });
expect(buildRows([cfg("a")], "cur").map((r) => r.type)).toEqual(["current", "edit"]);
expect(buildRows([cfg("a")], "cur").map((r) => r.type)).toEqual(["current", "section", "edit"]);
selectConfig(CURRENT_FILE);
expect(useRun.getState().selectedId).toBe(CURRENT_FILE);
});
+28
Переглянути файл
@@ -148,6 +148,8 @@ interface RunState {
pinned: string[];
/** Ids of the configurations started last, newest first (at most `MAX_RECENT`). */
recent: string[];
/** The chooser's "All Configurations" group is expanded (kept per project). */
allExpanded: boolean;
sessions: RunSession[];
activeSession: string | null;
/** Output version per session (re-render trigger for the console). */
@@ -175,6 +177,7 @@ export const useRun = create<RunState>(() => ({
temporary: [],
pinned: [],
recent: [],
allExpanded: false,
sessions: [],
activeSession: null,
versions: {},
@@ -245,6 +248,7 @@ export async function loadConfigs(): Promise<void> {
temporary: temps.map((t) => t.id),
pinned: readIds(PINNED_KEY, root),
recent: readIds(RECENT_KEY, root),
allExpanded: readAllExpanded(root),
loaded: true,
loadError: null,
selectedId,
@@ -275,8 +279,31 @@ export function selectConfig(id: string | null) {
const PINNED_KEY = "openidea.run.pinned:";
const RECENT_KEY = "openidea.run.recent:";
const ALL_EXPANDED_KEY = "openidea.run.allExpanded:";
export const MAX_RECENT = 5;
function readAllExpanded(root: string): boolean {
try {
return localStorage.getItem(ALL_EXPANDED_KEY + root) === "1";
} catch {
return false;
}
}
/** Expands or collapses the chooser's "All Configurations" group. Kept per project. */
export function toggleAllConfigurations() {
const allExpanded = !useRun.getState().allExpanded;
useRun.setState({ allExpanded });
const root = useProject.getState().project?.root;
if (!root) return;
try {
if (allExpanded) localStorage.setItem(ALL_EXPANDED_KEY + root, "1");
else localStorage.removeItem(ALL_EXPANDED_KEY + root);
} catch {
/* storage unavailable */
}
}
function readIds(key: string, root: string): string[] {
try {
const raw = JSON.parse(localStorage.getItem(key + root) ?? "[]") as unknown;
@@ -1534,6 +1561,7 @@ export function resetRuns() {
temporary: [],
pinned: [],
recent: [],
allExpanded: false,
sessions: [],
activeSession: null,
versions: {},
+2 -1
Переглянути файл
@@ -1776,5 +1776,6 @@
"Circular inheritance: '{name}' inherits from itself": "Circular inheritance: '{name}' inherits from itself",
"Method '{name}' is marked @override but no base class declares it": "Method '{name}' is marked @override but no base class declares it",
"Class '{name}' does not implement abstract method '{method}'": "Class '{name}' does not implement abstract method '{method}'",
"Redundant override of '{name}'": "Redundant override of '{name}'"
"Redundant override of '{name}'": "Redundant override of '{name}'",
"All Configurations": "All Configurations"
}
+2 -1
Переглянути файл
@@ -8177,5 +8177,6 @@
"PID {pid}": "进程号 {pid}",
"PID {pid} · {count} processes": "进程号 {pid} · {count} 个进程",
"End Process {label}": "结束进程 {label}",
"Diff too large: a side is over {max} MiB": "差异过大:有一侧超过 {max} MiB"
"Diff too large: a side is over {max} MiB": "差异过大:有一侧超过 {max} MiB",
"All Configurations": "所有配置"
}