fix(editor): group Quick Documentation popup actions (#4986)

Quick Documentation now keeps Edit Source and More Actions in its lower-right corner. More Actions groups the commands for opening the Documentation tool window and moving back or forward through the current document history. The corner stays visible while the documentation scrolls.
This commit is contained in:
l0ng-ai
2026-11-21 16:42:03 +08:00
committed by GitHub
parent bf2f44d523
commit 0d4bd4a69a
4 changed files with 118 additions and 44 deletions
+29 -13
View File
@@ -21,19 +21,33 @@ async function quickDocumentation(page: Page, markdown: string) {
test("short quick documentation uses a readable width and a compact corner of actions", async ({ workbench: page }) => {
const popup = await quickDocumentation(page, "Returns the total.");
const back = popup.getByRole("button", { name: "Back", exact: true });
const dock = popup.getByRole("button", { name: "Show in Documentation Tool Window" });
await expect(dock).toBeVisible();
const edit = popup.getByRole("button", { name: "Edit Source" });
const more = popup.getByRole("button", { name: "More Actions" });
await expect(edit).toBeVisible();
await expect(more).toBeVisible();
await expect(popup.getByRole("button")).toHaveCount(2);
const bounds = (await popup.boundingBox())!;
expect(bounds.width).toBeGreaterThanOrEqual(298);
expect(bounds.width).toBeLessThan(320);
const backBounds = (await back.boundingBox())!;
const dockBounds = (await dock.boundingBox())!;
expect(backBounds.x).toBeGreaterThan(bounds.x + bounds.width / 2);
expect(bounds.x + bounds.width - dockBounds.x - dockBounds.width).toBeLessThan(16);
const editBounds = (await edit.boundingBox())!;
const moreBounds = (await more.boundingBox())!;
expect(editBounds.x).toBeGreaterThan(bounds.x + bounds.width / 2);
expect(bounds.x + bounds.width - moreBounds.x - moreBounds.width).toBeLessThan(16);
await expect(popup.locator(".cm-lsp-markdown")).toHaveCSS("font-size", "13px");
await more.press("Enter");
const menu = page.getByRole("menu", { name: "More Actions" });
const dock = menu.getByRole("menuitem", { name: "Show in Documentation Tool Window" });
await expect(dock).toBeFocused();
await expect(menu.getByRole("menuitem", { name: "Back" })).toBeDisabled();
await expect(menu.getByRole("menuitem", { name: "Forward" })).toBeDisabled();
await page.keyboard.press("Escape");
await expect(menu).toBeHidden();
await expect(more).toBeFocused();
await expect(popup).toBeVisible();
await more.press("Enter");
await dock.press("Enter");
await expect(popup).toBeHidden();
await expect(page.locator('[data-lsp-doc="window"]')).toContainText("Returns the total.");
});
test("long quick documentation scrolls with its actions in view", async ({ workbench: page }) => {
@@ -46,8 +60,8 @@ test("long quick documentation scrolls with its actions in view", async ({ workb
"End of pricing documentation.",
].join("\n\n");
const popup = await quickDocumentation(page, markdown);
const dock = popup.getByRole("button", { name: "Show in Documentation Tool Window" });
await expect(dock).toBeVisible();
const more = popup.getByRole("button", { name: "More Actions" });
await expect(more).toBeVisible();
expect((await popup.boundingBox())!.width).toBeLessThan(508);
await page.setViewportSize({ width: 430, height: 500 });
await expect
@@ -58,7 +72,7 @@ test("long quick documentation scrolls with its actions in view", async ({ workb
.toBeLessThanOrEqual(1);
const body = popup.locator(".cm-lsp-markdown").locator("..");
const last = popup.getByText("End of pricing documentation.");
const dockBefore = (await dock.boundingBox())!;
const actionsBefore = (await more.boundingBox())!;
await expect(body.locator("pre")).toContainText(signature);
const scroll = await body.evaluate((node) => {
node.scrollTop = node.scrollHeight;
@@ -67,7 +81,9 @@ test("long quick documentation scrolls with its actions in view", async ({ workb
expect(scroll.top).toBeGreaterThan(0);
expect(scroll.horizontalOverflow).toBeLessThanOrEqual(1);
const lastBounds = (await last.boundingBox())!;
expect(lastBounds.y + lastBounds.height).toBeLessThanOrEqual(dockBefore.y + 1);
expect(await dock.boundingBox()).toEqual(dockBefore);
await expect(dock).toBeInViewport();
expect(lastBounds.y + lastBounds.height).toBeLessThanOrEqual(actionsBefore.y + 1);
expect(await more.boundingBox()).toEqual(actionsBefore);
await expect(more).toBeInViewport();
await more.click();
await expect(page.getByRole("menu", { name: "More Actions" })).toBeInViewport({ ratio: 1 });
});
+74 -23
View File
@@ -2,12 +2,13 @@
* The documentation view with its history toolbar, as IDEA's one documentation
* component: the F1 popup, the hover and the Documentation tool window show it.
*/
import { useLayoutEffect, useRef, type KeyboardEvent } from "react";
import { useLayoutEffect, useRef, useState, type KeyboardEvent } from "react";
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
import clsx from "clsx";
import { useStore } from "zustand";
import { IconButton, selectableText } from "@/ui";
import { IconButton, Menu, selectableText } from "@/ui";
import { useTx } from "@/platform/i18n";
import { shortcutLabel } from "@/platform/keymap";
import {
docLinkHandler,
@@ -40,8 +41,13 @@ export function DomContent({ build, className }: { build: () => HTMLElement; cla
export function DocView({ host, history, themeClasses }: { host: DocHost; history: DocHistory; themeClasses: string }) {
const entry = history.entries[history.index];
const tx = useTx();
const moreButton = useRef<HTMLButtonElement>(null);
const [moreOpen, setMoreOpen] = useState(false);
const atStart = history.index === 0;
const atEnd = history.index >= history.entries.length - 1;
const onKeyDown = (e: KeyboardEvent) => {
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
if (!e.currentTarget.contains(e.target as Node) || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
e.preventDefault();
docStep(host, e.key === "ArrowLeft" ? -1 : 1);
@@ -69,23 +75,27 @@ export function DocView({ host, history, themeClasses }: { host: DocHost; histor
/>
)}
<div className={styles.docToolbar}>
<IconButton
icon="arrow-left"
size="small"
title="Back"
shortcut="←"
disabled={history.index === 0}
onClick={() => docStep(host, -1)}
/>
<IconButton
icon="arrow-right"
size="small"
title="Forward"
shortcut="→"
disabled={history.index >= history.entries.length - 1}
onClick={() => docStep(host, 1)}
/>
<span className={styles.spacer} />
{host !== "popup" && (
<>
<IconButton
icon="arrow-left"
size="small"
title="Back"
shortcut="←"
disabled={atStart}
onClick={() => docStep(host, -1)}
/>
<IconButton
icon="arrow-right"
size="small"
title="Forward"
shortcut="→"
disabled={atEnd}
onClick={() => docStep(host, 1)}
/>
<span className={styles.spacer} />
</>
)}
{entry?.source && (
<IconButton
icon="edit"
@@ -95,15 +105,56 @@ export function DocView({ host, history, themeClasses }: { host: DocHost; histor
onClick={() => void editDocSource(host)}
/>
)}
{host !== "window" && (
{host === "popup" ? (
<>
<IconButton
ref={moreButton}
icon="more-horizontal"
size="small"
title="More Actions"
aria-haspopup="menu"
aria-expanded={moreOpen}
onClick={() => setMoreOpen((open) => !open)}
/>
<Menu
open={moreOpen}
onClose={() => setMoreOpen(false)}
anchor={moreButton}
placement="bottom-end"
aria-label={tx("More Actions")}
items={[
{
label: "Show in Documentation Tool Window",
icon: "open-in-tool-window",
shortcut: shortcutLabel("code.quickDocumentation") || undefined,
run: () => moveDocPopupToWindow(host),
},
{ kind: "separator" },
{
label: "Back",
icon: "arrow-left",
shortcut: "←",
disabled: atStart,
run: () => docStep(host, -1),
},
{
label: "Forward",
icon: "arrow-right",
shortcut: "→",
disabled: atEnd,
run: () => docStep(host, 1),
},
]}
/>
</>
) : host !== "window" ? (
<IconButton
icon="open-in-tool-window"
size="small"
title="Show in Documentation Tool Window"
shortcut={(host === "popup" && shortcutLabel("code.quickDocumentation")) || undefined}
onClick={() => moveDocPopupToWindow(host)}
/>
)}
) : null}
</div>
</div>
);
-3
View File
@@ -354,9 +354,6 @@
padding: 0;
border: 0;
}
.docPopup .docToolbar .spacer {
display: none;
}
.docWindowFrame {
height: 100%;
display: flex;
+15 -5
View File
@@ -235,12 +235,15 @@ describe("documentation", () => {
expect(container).toBeTruthy();
});
it("moves the popup to the Documentation tool window", () => {
it("navigates the popup history from More Actions and moves it to the Documentation tool window", () => {
openPopup({
kind: "doc",
anchor: { x: 0, y: 0 },
entries: [{ markup: { kind: "plaintext", value: "docs" }, language: null }],
index: 0,
entries: [
{ markup: { kind: "plaintext", value: "First document" }, language: null },
{ markup: { kind: "plaintext", value: "Second document" }, language: null },
],
index: 1,
themeClasses: "",
});
render(
@@ -249,10 +252,17 @@ describe("documentation", () => {
<DocumentationWindow />
</>,
);
fireEvent.click(screen.getByRole("button", { name: "Show in Documentation Tool Window" }));
const more = screen.getByRole("button", { name: "More Actions" });
fireEvent.click(more);
fireEvent.click(screen.getByRole("menuitem", { name: /^Back/ }));
expect(screen.getByText("First document")).toBeVisible();
fireEvent.click(more);
expect(screen.getByRole("menuitem", { name: /^Forward/ })).toBeEnabled();
fireEvent.click(screen.getByRole("menuitem", { name: /^Show in Documentation Tool Window/ }));
expect(useLspPopup.getState().popup).toBeNull();
expect(show).toHaveBeenCalledWith("documentation", true);
expect(useDocWindow.getState().entries).toHaveLength(1);
expect(useDocWindow.getState().entries).toHaveLength(2);
expect(useDocWindow.getState().index).toBe(0);
});
});