diff --git a/e2e/vimCommandLine.spec.ts b/e2e/vimCommandLine.spec.ts new file mode 100644 index 000000000..cf5e8f4d8 --- /dev/null +++ b/e2e/vimCommandLine.spec.ts @@ -0,0 +1,107 @@ +import type { Page } from "@playwright/test"; +import { expect, stubDesktop, test } from "./fixtures"; + +const FILE = "/dev/acme-api/command-line.txt"; + +async function openEditor(page: Page) { + const editor = page.locator(".cm-editor").first(); + await expect(editor).toHaveAttribute("data-openidea-vim", "true"); + await editor.locator(".cm-content").click(); + return editor; +} + +/** Computed type of one element: `null` when it is not in the DOM. */ +function fontOf(page: Page, selector: string) { + return page.evaluate((sel) => { + const el = document.querySelector(sel); + if (!el) return null; + const style = getComputedStyle(el); + return { + family: style.fontFamily, + size: style.fontSize, + ligatures: style.fontVariantLigatures, + }; + }, selector); +} + +test.beforeEach(async ({ page }) => { + test.setTimeout(180_000); + await page.addInitScript(() => + localStorage.setItem("openidea.vim.v1", JSON.stringify({ enabled: true, handlers: {} })), + ); + await page.goto("/"); + await expect(page.getByRole("tree", { name: "Project" })).toBeVisible(); + await stubDesktop(page); + await page.evaluate(async (path) => { + const backendPath = "/src/editor/core/backend.ts"; + const contributionsPath = "/src/workbench/contributions.ts"; + const { docBackend } = await import(backendPath); + const { editorService } = await import(contributionsPath); + docBackend().files.set(path, "alpha\nbravo\ncharlie\n"); + await editorService().openFile(path); + }, FILE); + await openEditor(page); +}); + +test("the command line renders in the editor's font", async ({ page }) => { + await page.keyboard.press(":"); + await expect(page.locator(".cm-vim-panel input")).toBeVisible(); + await page.keyboard.type("echo hello"); + + const prompt = await fontOf(page, ".cm-vim-panel input"); + // The package puts the prefix in a span with an inline `font-family: monospace`. + const prefix = await fontOf(page, ".cm-vim-panel span"); + const body = await fontOf(page, ".cm-scroller"); + + expect(prompt).not.toBeNull(); + expect(prefix).not.toBeNull(); + expect(body).not.toBeNull(); + expect(prompt!.family).toBe(body!.family); + expect(prompt!.size).toBe(body!.size); + expect(prefix!.family).toBe(prompt!.family); + expect(prefix!.size).toBe(prompt!.size); + // The browser's generic monospace (Consolas under WebView2) is what we are moving away from. + expect(prompt!.family).not.toBe("monospace"); + expect(prompt!.ligatures).toBe("none"); + + await page.keyboard.press("Escape"); +}); + +test("the search prompt shares the command line's font", async ({ page }) => { + await page.keyboard.press("/"); + await expect(page.locator(".cm-vim-panel input")).toBeVisible(); + await page.keyboard.type("alpha"); + + const prompt = await fontOf(page, ".cm-vim-panel input"); + const body = await fontOf(page, ".cm-scroller"); + expect(prompt).not.toBeNull(); + expect(body).not.toBeNull(); + expect(prompt!.family).toBe(body!.family); + expect(prompt!.size).toBe(body!.size); + + await page.keyboard.press("Escape"); +}); + +test("the command line follows the editor's font variables", async ({ page }) => { + // What Editor › Font and the zoom field write on the editor root. + await page.evaluate(() => { + const editor = document.querySelector(".cm-editor")!; + editor.style.setProperty("--openidea-editor-font", '"Sentinel Mono"'); + editor.style.setProperty("--openidea-editor-font-size", "21px"); + }); + + await page.keyboard.press(":"); + await expect(page.locator(".cm-vim-panel input")).toBeVisible(); + await page.keyboard.type("echo"); + + const prompt = await fontOf(page, ".cm-vim-panel input"); + const body = await fontOf(page, ".cm-scroller"); + expect(prompt).not.toBeNull(); + expect(body).not.toBeNull(); + expect(prompt!.family).toContain("Sentinel Mono"); + expect(prompt!.size).toBe("21px"); + expect(prompt!.family).toBe(body!.family); + expect(prompt!.size).toBe(body!.size); + + await page.keyboard.press("Escape"); +}); diff --git a/src/features/vim/engine.ts b/src/features/vim/engine.ts index a21994bbe..227d390de 100644 --- a/src/features/vim/engine.ts +++ b/src/features/vim/engine.ts @@ -361,12 +361,20 @@ const vimTheme = EditorView.theme({ padding: "2px 10px", minHeight: "1.6em", alignItems: "center", - fontFamily: "var(--font-mono)", - fontSize: "var(--fs-code)", + // The command line is text like the code above it: same configured font and zoom. + fontFamily: "var(--openidea-editor-font, var(--font-mono))", + fontSize: "var(--openidea-editor-font-size, var(--fs-code))", + fontVariantLigatures: "none", background: "var(--bg-elev)", color: "var(--fg)", borderTop: "1px solid var(--border)", }, + // The package writes `font-family: monospace` inline on the span that holds the prefix + // and the input; only an important rule beats an inline declaration, and `inherit` then + // picks up the panel's font. + ".cm-vim-panel span": { fontFamily: "inherit !important" }, + // Ligatures follow the editor's toggle, as the scroller's pair does. + "&.cm-openidea-ligatures .cm-vim-panel": { fontVariantLigatures: "normal" }, ".cm-vim-panel input": { color: "var(--fg)", fontFamily: "inherit", fontSize: "inherit" }, });