mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-25 00:03:08 +00:00
fix(build-tools): select a clicked completion in Execute Maven Goal / Gradle Task instead of appending it (#2785)
Clicking a completion appended it to the command line and re-filtered the list, so repeated clicks kept accumulating goals. A click now selects the row and shows its command line in the input; another click switches to that row; the list filters only on typing; Enter or a double-click runs it. Goals and tasks already on the command line are no longer offered again. Co-authored-by: PLZY <+PLZY@users.noreply.github.com>
This commit is contained in:
@@ -47,7 +47,7 @@ it("starts PageUp on a completion rather than a section", () => {
|
||||
render(<ExecutePopupHost />);
|
||||
const input = screen.getByRole("textbox");
|
||||
fireEvent.keyDown(input, { key: "PageUp" });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
fireEvent.keyDown(input, { key: "Tab" });
|
||||
expect(input).toHaveValue("clean ");
|
||||
});
|
||||
|
||||
@@ -96,10 +96,21 @@ it("PageDown selects a completion rather than a section at its landing position"
|
||||
const input = screen.getByRole("textbox");
|
||||
fireEvent.keyDown(input, { key: "ArrowDown" });
|
||||
fireEvent.keyDown(input, { key: "PageDown" });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
fireEvent.keyDown(input, { key: "Tab" });
|
||||
expect(input).toHaveValue(`${goalCompletions("", [])[0]!.line} `);
|
||||
});
|
||||
|
||||
it("shows a clicked completion in the input instead of appending it", () => {
|
||||
render(<ExecutePopupHost />);
|
||||
const input = screen.getByRole("textbox");
|
||||
const options = screen.getAllByRole("option");
|
||||
fireEvent.click(options[0]!);
|
||||
expect(input).toHaveValue("clean");
|
||||
fireEvent.click(options[1]!);
|
||||
expect(input).toHaveValue("validate");
|
||||
expect(screen.getAllByRole("option")).toHaveLength(options.length);
|
||||
});
|
||||
|
||||
it("resets selection when changing the Gradle build used for completion", () => {
|
||||
const build = (dir: string, name: string): GradleModel => ({
|
||||
dir,
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* "Execute Maven Goal" / "Execute Gradle Task" (IDEA's Run Anything popup for a
|
||||
* build tool): a command line with completion of lifecycle phases and plugin
|
||||
* goals (Maven) or task names / paths (Gradle), plus recent command lines.
|
||||
* Tab or a click accepts a completion; Enter runs the line in the chosen project.
|
||||
* Tab completes the word. Selecting a row (click or arrows) shows its command line in the input;
|
||||
* Enter or a double-click runs it (or the typed line) in the chosen project.
|
||||
*/
|
||||
import { useMemo, useState, type KeyboardEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
@@ -89,8 +90,11 @@ function ExecutePopup({ tool }: { tool: BuildTool }) {
|
||||
|
||||
const close = () => useBuild.setState({ executeOpen: null });
|
||||
|
||||
const execute = () => {
|
||||
const text = line.trim();
|
||||
const selectedRow = active >= 0 ? rows[active] : undefined;
|
||||
const selected = selectedRow?.kind === "completion" ? selectedRow.completion : null;
|
||||
|
||||
const execute = (command = selected?.line ?? line) => {
|
||||
const text = command.trim();
|
||||
if (text && executeBuildLine(tool, text, project)) close();
|
||||
};
|
||||
|
||||
@@ -115,8 +119,7 @@ function ExecutePopup({ tool }: { tool: BuildTool }) {
|
||||
accept(rows[active < 0 ? firstCompletion : active]);
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (active >= 0) accept(rows[active]);
|
||||
else execute();
|
||||
execute();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -147,7 +150,7 @@ function ExecutePopup({ tool }: { tool: BuildTool }) {
|
||||
data-autofocus
|
||||
variant="bare"
|
||||
className={styles.input}
|
||||
value={line}
|
||||
value={selected?.line ?? line}
|
||||
placeholder={tool === "maven" ? "clean install -DskipTests" : "build --info"}
|
||||
aria-label={tool === "maven" ? "Maven command line" : "Gradle command line"}
|
||||
onChange={(e) => {
|
||||
@@ -166,7 +169,11 @@ function ExecutePopup({ tool }: { tool: BuildTool }) {
|
||||
)}
|
||||
activeIndex={active}
|
||||
onActiveChange={setActive}
|
||||
onActivate={(c) => accept(c)}
|
||||
onActivate={(row, index, e) => {
|
||||
if (row.kind !== "completion") return;
|
||||
setActive(index);
|
||||
if (e.detail >= 2) execute(row.completion.line);
|
||||
}}
|
||||
focusable={false}
|
||||
hoverSelects={false}
|
||||
rowHeight={24}
|
||||
|
||||
@@ -272,6 +272,8 @@ describe("Maven runs", () => {
|
||||
expect(goalCompletions("sure", [surefire]).map((x) => x.label)).toEqual(["surefire:help", "surefire:test"]);
|
||||
expect(goalCompletions("cl", [], ["clean install"]).map((x) => x.label)[0]).toBe("clean install");
|
||||
expect(goalCompletions("-D", [surefire])).toEqual([]);
|
||||
expect(goalCompletions("mvn clean test ", [surefire]).map((x) => x.label)).not.toContain("test");
|
||||
expect(goalCompletions("clean c", []).map((x) => x.label)).not.toContain("clean");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -456,6 +458,8 @@ describe("Gradle tree and runs", () => {
|
||||
const labelsOf = taskCompletions("ru", gradle).map((c) => c.label);
|
||||
expect(labelsOf).toEqual([":app:run"]);
|
||||
expect(taskCompletions("clean wr", gradle).map((c) => c.line)).toEqual(["clean wrapper"]);
|
||||
expect(taskCompletions("wrapper wr", gradle)).toEqual([]);
|
||||
expect(taskCompletions(":app:run ", gradle).map((c) => c.label)).not.toContain(":app:run");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -594,7 +594,8 @@ export function goalCompletions(
|
||||
const head = line.slice(0, at);
|
||||
const word = line.slice(at).toLowerCase();
|
||||
const out: Completion[] = [];
|
||||
const seen = new Set<string>();
|
||||
// Already-typed goals are not offered again.
|
||||
const seen = new Set<string>(parseGoalLine(head));
|
||||
const push = (label: string, detail?: string) => {
|
||||
if (seen.has(label) || !label.toLowerCase().startsWith(word)) return;
|
||||
seen.add(label);
|
||||
@@ -618,7 +619,8 @@ export function taskCompletions(line: string, model: GradleModel, history: reado
|
||||
const head = line.slice(0, at);
|
||||
const word = line.slice(at).toLowerCase();
|
||||
const out: Completion[] = [];
|
||||
const seen = new Set<string>();
|
||||
// Already-typed tasks are not offered again.
|
||||
const seen = new Set<string>(parseTaskLine(head));
|
||||
if (!head.trim())
|
||||
for (const h of history)
|
||||
if (h.toLowerCase().startsWith(line.toLowerCase()) && h !== line)
|
||||
|
||||
Reference in New Issue
Block a user