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

...
Автор SHA1 Повідомлення Дата
l0ng-ai 3bac82c9a9 fix: Delete in a popup's search field edits the text before it removes the selection
Open Recent removed the selected project on Delete wherever the caret was in
the search field, and the run configuration chooser deleted the selected
configuration without asking. Delete now acts on the selection only when it
has no text to delete (the caret at the end of the query, nothing selected;
⌘⌫ only with an empty query), and the chooser asks before deleting a
configuration, from Delete or its menu, as IDEA's popup does.

Fixes #4159
Fixes #4203
2026-11-18 18:47:51 +08:00
6 змінених файлів з 65 додано та 9 видалено

No files matched your search

+15 -3
Переглянути файл
@@ -36,6 +36,7 @@ import {
import { selectedTarget } from "./sessionTargets";
import styles from "./Run.module.css";
import { tx } from "@/platform/i18n";
import { confirm } from "@/workbench/messages";
type Row =
/** A labelled group, or a thin separator when `label` is empty. */
@@ -111,6 +112,16 @@ function anchorElement(): Element | { x: number; y: number } {
}
/** Run/Debug configuration chooser popup (⌃⌥R), anchored to the title bar widget. */
/** Deletes a configuration from the chooser once the user confirms, as IDEA's popup asks first. */
async function askDeleteConfig(config: RunConfig) {
const ok = await confirm({
title: "Confirmation",
message: tx`Are you sure you want to delete ${config.name}?`,
ok: "Delete",
});
if (ok) await deleteConfig(config.id);
}
export function ConfigChooserOverlay() {
const open = useRun((s) => s.chooserOpen);
if (!open) return null;
@@ -250,10 +261,11 @@ function ConfigChooser() {
e.key === "Delete" &&
row?.type === "config" &&
canDeleteConfig(row.config.id) &&
input().selectionStart === query.length
input().selectionStart === query.length &&
input().selectionEnd === query.length
) {
e.preventDefault();
void deleteConfig(row.config.id);
void askDeleteConfig(row.config);
return;
}
if (numbers.size && !e.altKey && !e.ctrlKey && !e.metaKey && /^Digit[1-9]$|^Numpad[1-9]$/.test(e.code)) {
@@ -286,7 +298,7 @@ function ConfigChooser() {
{ 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) }] : []),
...(canDeleteConfig(c.id) ? [{ label: "Delete", danger: true, run: () => void askDeleteConfig(c) }] : []),
];
};
const openMenu = (c: RunConfig, at: Element) => setMenu({ name: c.name, anchor: at, items: menuItems(c) });
+29 -3
Переглянути файл
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
const ipc = vi.hoisted(() => ({
runSaveConfigs: vi.fn(),
@@ -17,6 +17,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => ({
import type { RunConfig } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { MessagesHost } from "@/workbench/messages";
import { EditConfigsOverlay } from "./EditConfigsDialog";
import { ConfigChooserOverlay } from "./ConfigChooser";
import {
@@ -141,14 +142,39 @@ it("keeps other temporary and non-temporary configurations on removal", async ()
expect(useRun.getState().configs.map((c) => c.id)).toEqual(expect.arrayContaining(["npm:app", other.id]));
});
it("chooser popup Delete removes the selected detection", async () => {
it("chooser popup Delete removes the selected detection once confirmed", async () => {
useRun.setState({ chooserOpen: true, editorOpen: false });
render(<ConfigChooserOverlay />);
render(
<>
<ConfigChooserOverlay />
<MessagesHost />
</>,
);
fireEvent.keyDown(document.querySelector("input[data-autofocus]")!, { key: "Delete" });
const ask = await screen.findByRole("dialog", { name: "Confirmation" });
expect(ipc.runSaveConfigs).not.toHaveBeenCalled();
fireEvent.click(within(ask).getByRole("button", { name: "Delete" }));
await waitFor(() => expect(ipc.runSaveConfigs).toHaveBeenCalledWith([], ["npm:app"]));
await waitFor(() => expect(useRun.getState().configs).toEqual([]));
});
it("chooser popup Delete edits the search text when the caret is not at its end", async () => {
useRun.setState({ chooserOpen: true, editorOpen: false });
render(
<>
<ConfigChooserOverlay />
<MessagesHost />
</>,
);
const input = document.querySelector<HTMLInputElement>("input[data-autofocus]")!;
fireEvent.change(input, { target: { value: "app" } });
input.setSelectionRange(1, 1);
fireEvent.keyDown(input, { key: "Delete" });
await act(async () => {});
expect(screen.queryByRole("dialog", { name: "Confirmation" })).toBeNull();
expect(ipc.runSaveConfigs).not.toHaveBeenCalled();
});
it("Cancel discards a pending detected removal", () => {
render(<EditConfigsOverlay />);
fireEvent.click(screen.getByRole("button", { name: "Remove Configuration" }));
+5 -1
Переглянути файл
@@ -274,7 +274,11 @@ export function RecentList({ exclude, compact, autoFocus, onOpened, className, t
open(items[current]);
return;
}
if ((e.key === "Delete" || (e.key === "Backspace" && e.metaKey)) && items[current]) {
// Delete removes the selected project only when it has no text to delete: the caret is at the end
// of the query (⌘⌫: the query is empty). Otherwise it edits the query.
const field = e.currentTarget;
const atEnd = field.selectionStart === field.value.length && field.selectionEnd === field.value.length;
if (((e.key === "Delete" && atEnd) || (e.key === "Backspace" && e.metaKey && !field.value)) && items[current]) {
e.preventDefault();
void askRemoveRecent(items[current]!.project);
return;
+12
Переглянути файл
@@ -137,6 +137,18 @@ describe("Welcome › Projects", () => {
expect(selectedName()).toBe("py-demo");
});
it("leaves Delete to the search text while the caret has text after it", async () => {
await renderWelcome();
const search = screen.getByLabelText("Search projects") as HTMLInputElement;
fireEvent.change(search, { target: { value: "acme" } });
search.setSelectionRange(1, 1);
fireEvent.keyDown(search, { key: "Delete" });
expect(screen.queryByRole("dialog", { name: "Remove Recent Project" })).toBeNull();
search.setSelectionRange(4, 4);
fireEvent.keyDown(search, { key: "Delete" });
expect(screen.getByRole("dialog", { name: "Remove Recent Project" })).toBeTruthy();
});
it("offers Open in New Window in the row menu when the action exists", async () => {
const dispose = registerActions([{ id: "file.openInNewWindow", title: "Open in New Window", run: () => {} }]);
await renderWelcome();
+2 -1
Переглянути файл
@@ -2478,5 +2478,6 @@
"Alignment": "Alignment",
"Align key-value pairs": "Align key-value pairs",
"Align consecutive assignments": "Align consecutive assignments",
"Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.": "Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines."
"Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.": "Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.",
"Are you sure you want to delete {name}?": "Are you sure you want to delete {name}?"
}
+2 -1
Переглянути файл
@@ -8853,5 +8853,6 @@
"Alignment": "对齐",
"Align key-value pairs": "对齐键值对",
"Align consecutive assignments": "对齐连续赋值",
"Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.": "在语言服务器或 PHP-CS-Fixer 格式化文件后,对齐多行数组中的 => 和连续赋值语句中的 =;格式化选区时只对齐选中的行。"
"Lines up => in multi-line arrays and = in consecutive assignments after the language server or PHP-CS-Fixer formats the file; for a selection, only its lines.": "在语言服务器或 PHP-CS-Fixer 格式化文件后,对齐多行数组中的 => 和连续赋值语句中的 =;格式化选区时只对齐选中的行。",
"Are you sure you want to delete {name}?": "确定要删除 {name} 吗?"
}