diff --git a/e2e/quickDocumentationLayout.spec.ts b/e2e/quickDocumentationLayout.spec.ts index 19d33315b..1651bc311 100644 --- a/e2e/quickDocumentationLayout.spec.ts +++ b/e2e/quickDocumentationLayout.spec.ts @@ -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 }); }); diff --git a/src/editor/lsp/DocView.tsx b/src/editor/lsp/DocView.tsx index 63bc1137b..7c1afb364 100644 --- a/src/editor/lsp/DocView.tsx +++ b/src/editor/lsp/DocView.tsx @@ -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(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 /> )}
- docStep(host, -1)} - /> - = history.entries.length - 1} - onClick={() => docStep(host, 1)} - /> - + {host !== "popup" && ( + <> + docStep(host, -1)} + /> + docStep(host, 1)} + /> + + + )} {entry?.source && ( void editDocSource(host)} /> )} - {host !== "window" && ( + {host === "popup" ? ( + <> + setMoreOpen((open) => !open)} + /> + 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" ? ( moveDocPopupToWindow(host)} /> - )} + ) : null}
); diff --git a/src/editor/lsp/Popups.module.css b/src/editor/lsp/Popups.module.css index 466100ea7..29a306830 100644 --- a/src/editor/lsp/Popups.module.css +++ b/src/editor/lsp/Popups.module.css @@ -354,9 +354,6 @@ padding: 0; border: 0; } -.docPopup .docToolbar .spacer { - display: none; -} .docWindowFrame { height: 100%; display: flex; diff --git a/src/editor/lsp/Popups.test.tsx b/src/editor/lsp/Popups.test.tsx index 507ce579f..530cf3dde 100644 --- a/src/editor/lsp/Popups.test.tsx +++ b/src/editor/lsp/Popups.test.tsx @@ -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", () => { , ); - 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); }); });