diff --git a/src/features/build-tools/ExecutePopup.test.tsx b/src/features/build-tools/ExecutePopup.test.tsx
index f24f80f56..f6d7282c6 100644
--- a/src/features/build-tools/ExecutePopup.test.tsx
+++ b/src/features/build-tools/ExecutePopup.test.tsx
@@ -47,7 +47,7 @@ it("starts PageUp on a completion rather than a section", () => {
render();
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();
+ 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,
diff --git a/src/features/build-tools/ExecutePopup.tsx b/src/features/build-tools/ExecutePopup.tsx
index 77d731f27..fbac2b5cd 100644
--- a/src/features/build-tools/ExecutePopup.tsx
+++ b/src/features/build-tools/ExecutePopup.tsx
@@ -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}
diff --git a/src/features/build-tools/model.test.ts b/src/features/build-tools/model.test.ts
index 93c77ba3b..913fbf250 100644
--- a/src/features/build-tools/model.test.ts
+++ b/src/features/build-tools/model.test.ts
@@ -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");
});
});
diff --git a/src/features/build-tools/model.ts b/src/features/build-tools/model.ts
index dc1895135..5a3908f2b 100644
--- a/src/features/build-tools/model.ts
+++ b/src/features/build-tools/model.ts
@@ -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();
+ // Already-typed goals are not offered again.
+ const seen = new Set(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();
+ // Already-typed tasks are not offered again.
+ const seen = new Set(parseTaskLine(head));
if (!head.trim())
for (const h of history)
if (h.toLowerCase().startsWith(line.toLowerCase()) && h !== line)