дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
feat(bookmarks): select and rename lists in the popup (#6849)
List headers in the Bookmarks popup are now selectable rows; F2 on one opens the list name dialog, while file section rows stay non-selectable and are skipped by the keyboard. The popup claims F2 while its list is focused so the global Rename File shortcut does not take it. Co-authored-by: muutot <[email protected]>
Цей коміт міститься в:
1 джерело
94ddb1807d
коміт
c8efb2917d
3 files changed
+152
-17
No files matched your search
@@ -9,6 +9,15 @@ async function bookmarkAction(page: Page, id: "navigate.toggleBookmark" | "navig
|
||||
}, id);
|
||||
}
|
||||
|
||||
async function defaultBookmarkListName(page: Page) {
|
||||
return page.evaluate(async () => {
|
||||
const path = "/src/features/search/bookmarks/store.ts";
|
||||
const { useBookmarks } = await import(/* @vite-ignore */ path);
|
||||
const { lists, defaultList } = useBookmarks.getState();
|
||||
return lists.find((item: { id: string }) => item.id === defaultList)!.name as string;
|
||||
});
|
||||
}
|
||||
|
||||
test("Bookmarks remembers its size and keeps the list and preview usable in a narrow window", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
@@ -32,6 +41,8 @@ test("Bookmarks remembers its size and keeps the list and preview usable in a na
|
||||
const divider = dialog.getByRole("separator", { name: "Resize bookmark panes", exact: true });
|
||||
await expect(divider).toHaveAttribute("aria-orientation", "vertical");
|
||||
await expect(list).toBeFocused();
|
||||
await expect(list.getByRole("option", { selected: true })).toHaveText(await defaultBookmarkListName(page));
|
||||
await list.press("ArrowDown");
|
||||
await expect(list.getByRole("option", { selected: true })).toContainText(first);
|
||||
await expect(preview.locator(".cm-activeLine")).toContainText(first);
|
||||
const lineNumbers = list.getByRole("option").locator(":scope > span > span:last-child");
|
||||
@@ -75,6 +86,7 @@ test("Bookmarks remembers its size and keeps the list and preview usable in a na
|
||||
expect(narrowPreview.height).toBeGreaterThan(100);
|
||||
await expect(dialog).toBeInViewport({ ratio: 1 });
|
||||
|
||||
await list.press("ArrowDown");
|
||||
await list.press("ArrowDown");
|
||||
await expect(list.getByRole("option", { selected: true })).toContainText(second);
|
||||
await expect(preview.locator(".cm-activeLine")).toContainText(second);
|
||||
@@ -83,3 +95,37 @@ test("Bookmarks remembers its size and keeps the list and preview usable in a na
|
||||
await expect(editor.locator(".cm-activeLine")).toContainText(second);
|
||||
expect(resizeErrors).toEqual([]);
|
||||
});
|
||||
|
||||
test("Bookmarks selects list headers, skips file sections, and renames a list with F2", async ({ workbench: page }) => {
|
||||
const editor = await openFromTree(page, "build.gradle.kts");
|
||||
const line = "val order: Order = service.create(req)";
|
||||
await editor.locator(".cm-line", { hasText: line }).click();
|
||||
await bookmarkAction(page, "navigate.toggleBookmark");
|
||||
await bookmarkAction(page, "navigate.showBookmarks");
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Bookmarks", exact: true });
|
||||
const list = dialog.getByRole("listbox", { name: "Bookmarks" });
|
||||
const originalName = await defaultBookmarkListName(page);
|
||||
await expect(list).toBeFocused();
|
||||
await expect(list.getByRole("option", { selected: true })).toHaveText(originalName);
|
||||
await expect(list.getByRole("option")).toHaveCount(2);
|
||||
|
||||
await list.press("ArrowDown");
|
||||
await expect(list.getByRole("option", { selected: true })).toContainText(line);
|
||||
await list.press("ArrowUp");
|
||||
await expect(list.getByRole("option", { selected: true })).toHaveText(originalName);
|
||||
await list.press("F2");
|
||||
|
||||
const rename = page.getByRole("dialog", { name: "Rename Bookmark List", exact: true });
|
||||
const input = rename.getByLabel("List name");
|
||||
await expect(input).toHaveValue(originalName);
|
||||
await input.fill("Reading list");
|
||||
await input.press("Enter");
|
||||
await expect(rename).toBeHidden();
|
||||
await expect(list.getByRole("option", { selected: true })).toHaveText("Reading list");
|
||||
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(dialog).toBeHidden();
|
||||
await bookmarkAction(page, "navigate.showBookmarks");
|
||||
await expect(list.getByRole("option", { selected: true })).toHaveText("Reading list");
|
||||
});
|
||||
@@ -19,7 +19,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
act(() => useBookmarkPopups.setState({ chooser: null, list: false, editing: null }));
|
||||
act(() => useBookmarkPopups.setState({ chooser: null, list: false, editing: null, naming: null }));
|
||||
});
|
||||
|
||||
const set = (items: Bookmark[]) => act(() => updateBookmarks(() => items));
|
||||
@@ -60,6 +60,8 @@ describe("Bookmarks popup", () => {
|
||||
act(() => useBookmarkPopups.setState({ list: true }));
|
||||
const list = screen.getByRole("listbox", { name: "Bookmarks" });
|
||||
expect(screen.getByText("five")).toBeInTheDocument();
|
||||
// The list header is selected first; ArrowDown skips the file section.
|
||||
fireEvent.keyDown(list, { key: "ArrowDown" });
|
||||
fireEvent.keyDown(list, { key: "Delete" });
|
||||
expect(useBookmarks.getState().items.map((b) => b.line)).toEqual([5, 0]);
|
||||
fireEvent.keyDown(list, { key: "F2" });
|
||||
@@ -69,6 +71,84 @@ describe("Bookmarks popup", () => {
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(useBookmarks.getState().items[0]!.description).toBe("main");
|
||||
});
|
||||
|
||||
it("selects list headers and skips non-selectable file rows", () => {
|
||||
set([
|
||||
{ path: "/p/a", line: 0, text: "one", created: 1 },
|
||||
{ path: "/p/b", line: 0, text: "two", created: 2 },
|
||||
]);
|
||||
render(<BookmarkPopupsOverlay />);
|
||||
act(() => useBookmarkPopups.setState({ list: true }));
|
||||
const list = screen.getByRole("listbox", { name: "Bookmarks" });
|
||||
const options = () => screen.getAllByRole("option");
|
||||
expect(options()).toHaveLength(3);
|
||||
expect(options()[0]).toHaveTextContent("p");
|
||||
expect(options()[0]).toHaveAttribute("aria-selected", "true");
|
||||
|
||||
fireEvent.keyDown(list, { key: "ArrowDown" });
|
||||
expect(options()[1]).toHaveTextContent("one");
|
||||
expect(options()[1]).toHaveAttribute("aria-selected", "true");
|
||||
fireEvent.keyDown(list, { key: "ArrowDown" });
|
||||
expect(options()[2]).toHaveTextContent("two");
|
||||
expect(options()[2]).toHaveAttribute("aria-selected", "true");
|
||||
fireEvent.keyDown(list, { key: "ArrowUp" });
|
||||
expect(options()[1]).toHaveAttribute("aria-selected", "true");
|
||||
fireEvent.keyDown(list, { key: "ArrowUp" });
|
||||
expect(options()[0]).toHaveAttribute("aria-selected", "true");
|
||||
});
|
||||
|
||||
it("cancels F2 list renaming without changing the selected list", () => {
|
||||
set([{ path: "/p/a", line: 0, text: "one", created: 1 }]);
|
||||
render(<BookmarkPopupsOverlay />);
|
||||
act(() => useBookmarkPopups.setState({ list: true }));
|
||||
fireEvent.keyDown(screen.getByRole("listbox", { name: "Bookmarks" }), { key: "F2" });
|
||||
expect(useBookmarkPopups.getState().naming).toEqual({ listId: "default" });
|
||||
const input = screen.getByLabelText("List name");
|
||||
expect(input).toHaveValue("p");
|
||||
fireEvent.change(input, { target: { value: "Discarded" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
|
||||
expect(useBookmarkPopups.getState().naming).toBeNull();
|
||||
expect(useBookmarks.getState().lists).toEqual([{ id: "default", name: "p" }]);
|
||||
expect(screen.getByRole("option", { name: "p", selected: true })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renames a selected list header with F2 using its structural list id", () => {
|
||||
act(() =>
|
||||
updateBookmarkData((d) => ({
|
||||
...d,
|
||||
lists: [...d.lists, { id: "list2", name: "Review" }],
|
||||
items: [
|
||||
{ path: "/p/a", line: 0, text: "one", created: 1, list: "default" },
|
||||
{ path: "/p/b", line: 0, text: "two", created: 2, list: "list2" },
|
||||
],
|
||||
})),
|
||||
);
|
||||
const { items, lists } = useBookmarks.getState();
|
||||
expect(bookmarkRows(items, [], lists).filter((r) => r.kind === "list")).toEqual([
|
||||
{ kind: "list", key: "l:default", listId: "default", name: "p" },
|
||||
{ kind: "list", key: "l:list2", listId: "list2", name: "Review" },
|
||||
]);
|
||||
render(<BookmarkPopupsOverlay />);
|
||||
act(() => useBookmarkPopups.setState({ list: true }));
|
||||
const review = screen.getByRole("option", { name: "Review" });
|
||||
fireEvent.mouseDown(review, { button: 0 });
|
||||
expect(review).toHaveAttribute("aria-selected", "true");
|
||||
fireEvent.keyDown(screen.getByRole("listbox", { name: "Bookmarks" }), { key: "F2" });
|
||||
expect(useBookmarkPopups.getState().naming).toEqual({ listId: "list2" });
|
||||
const input = screen.getByLabelText("List name");
|
||||
expect(input).toHaveValue("Review");
|
||||
fireEvent.change(input, { target: { value: " Approved " } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
|
||||
expect(useBookmarkPopups.getState().naming).toBeNull();
|
||||
expect(useBookmarks.getState().lists).toEqual([
|
||||
{ id: "default", name: "p" },
|
||||
{ id: "list2", name: "Approved" },
|
||||
]);
|
||||
expect(useBookmarks.getState().items.find((b) => b.path === "/p/b")?.list).toBe("list2");
|
||||
expect(screen.getByRole("option", { name: "Approved", selected: true })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Bookmarks popup with file and folder bookmarks", () => {
|
||||
@@ -104,7 +184,9 @@ describe("Bookmarks popup with file and folder bookmarks", () => {
|
||||
render(<BookmarkPopupsOverlay />);
|
||||
act(() => useBookmarkPopups.setState({ list: true }));
|
||||
expect(screen.getByText("Review")).toBeInTheDocument();
|
||||
// The folder is the first selectable row: Enter selects it in the project view.
|
||||
expect(screen.getByRole("option", { name: "p", selected: true })).toBeInTheDocument();
|
||||
// The list header is selected first; ArrowDown selects the folder.
|
||||
fireEvent.keyDown(screen.getByRole("listbox", { name: "Bookmarks" }), { key: "ArrowDown" });
|
||||
vi.useFakeTimers();
|
||||
fireEvent.keyDown(screen.getByRole("listbox", { name: "Bookmarks" }), { key: "Enter" });
|
||||
vi.runAllTimers();
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
* popup (⌘F3: line, file and folder bookmarks by list + preview; Enter jumps), the Edit Description dialog
|
||||
* (F2 / Rename) and the bookmark list name dialog (New List / Rename List).
|
||||
*/
|
||||
import { useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent } from "react";
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent } from "react";
|
||||
import clsx from "clsx";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { registerKeyClaim } from "@/platform/keymap";
|
||||
import { useProject } from "@/platform/project";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -152,7 +153,7 @@ function MnemonicChooser() {
|
||||
// --- Bookmarks popup ------------------------------------------------------------
|
||||
|
||||
type Row =
|
||||
| { kind: "list"; key: string; name: string }
|
||||
| { kind: "list"; key: string; listId: string; name: string }
|
||||
/** A file with line bookmarks only (a section header). */
|
||||
| { kind: "file"; key: string; path: string }
|
||||
/** A bookmarked file or folder. */
|
||||
@@ -191,13 +192,13 @@ export function bookmarkRows(
|
||||
const marks = items.filter((b) => b.list === l.id);
|
||||
const marked = paths.filter((p) => p.list === l.id);
|
||||
if (!marks.length && !marked.length) continue;
|
||||
rows.push({ kind: "list", key: `l:${l.id}`, name: l.name });
|
||||
rows.push({ kind: "list", key: `l:${l.id}`, listId: l.id, name: l.name });
|
||||
group(l.id, marks, marked);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
const isSectionRow = (r: Row) => r.kind === "file" || r.kind === "list";
|
||||
const isSectionRow = (r: Row) => r.kind === "file";
|
||||
|
||||
const BOOKMARK_POPUP_SIZE = "openidea.bookmarks.popupSize";
|
||||
const MIN_WIDTH = 340;
|
||||
@@ -243,8 +244,14 @@ function BookmarksPopup() {
|
||||
const active = Math.min(index, rows.length - 1);
|
||||
const row = rows[active];
|
||||
const selected = row?.kind === "mark" ? row.bookmark : null;
|
||||
const selectedList = row?.kind === "list" ? row : null;
|
||||
const selectedPath = row?.kind === "path" ? row : null;
|
||||
const close = () => useBookmarkPopups.setState({ list: false });
|
||||
useEffect(
|
||||
() =>
|
||||
registerKeyClaim((e, stroke) => stroke === "F2" && !!(e.target as Element | null)?.closest?.("#bookmark-list")),
|
||||
[],
|
||||
);
|
||||
const jump = (r: Row | undefined) => {
|
||||
if (r?.kind !== "mark" && r?.kind !== "path") return;
|
||||
close();
|
||||
@@ -261,13 +268,17 @@ function BookmarksPopup() {
|
||||
updateBookmarkData((d) => ({ ...d, paths: d.paths.filter((p) => p.path !== selectedPath.path) }));
|
||||
return;
|
||||
}
|
||||
if (e.key === "F2" && (selectedList || selected)) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (selectedList) useBookmarkPopups.setState({ naming: { listId: selectedList.listId } });
|
||||
else if (selected) useBookmarkPopups.setState({ editing: { path: selected.path, line: selected.line } });
|
||||
return;
|
||||
}
|
||||
if (!selected) return;
|
||||
if (e.key === "Delete" || e.key === "Backspace") {
|
||||
e.preventDefault();
|
||||
updateBookmarks((list) => removeBookmarks(list, (b) => b.path === selected.path && b.line === selected.line));
|
||||
} else if (e.key === "F2") {
|
||||
e.preventDefault();
|
||||
useBookmarkPopups.setState({ editing: { path: selected.path, line: selected.line } });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -321,15 +332,11 @@ function BookmarksPopup() {
|
||||
autoFocus
|
||||
rowHeight={rowHeight}
|
||||
empty={<span>{items.length || paths.length ? null : <T>No bookmarks</T>}</span>}
|
||||
renderSection={(r) =>
|
||||
r.kind === "file" ? (
|
||||
fileLabel(r.path, false)
|
||||
) : r.kind === "list" ? (
|
||||
<span className={styles.listRow}>{r.name}</span>
|
||||
) : null
|
||||
}
|
||||
renderSection={(r) => (r.kind === "file" ? fileLabel(r.path, false) : null)}
|
||||
renderItem={(r) =>
|
||||
r.kind === "path" ? (
|
||||
r.kind === "list" ? (
|
||||
<span className={styles.listRow}>{r.name}</span>
|
||||
) : r.kind === "path" ? (
|
||||
fileLabel(r.path, r.dir)
|
||||
) : r.kind === "mark" ? (
|
||||
<span className={styles.markRow}>
|
||||
|
||||
Reference in new issue
Заблокувати користувача