import type { Page } from "@playwright/test"; import { expect, stubDesktop, test } from "./fixtures"; const FILE = "/dev/acme-api/undo-break.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; } /** Applies rc file lines through the same parser and engine the app uses. */ async function applyRc(page: Page, rc: string) { await page.evaluate(async (text) => { // Load the app modules in the browser's Vite realm; the variables keep knip from resolving the URLs. const enginePath = "/src/features/vim/engine.ts"; const rcPath = "/src/features/vim/rc.ts"; const { applyRcCommands } = await import(enginePath); const { parseVimrc } = await import(rcPath); applyRcCommands(parseVimrc(text).commands); }, rc); } const documentText = (page: Page) => page.evaluate(async () => { // Load the app module in the browser's Vite realm; the variable keeps knip from resolving the URL. const apiPath = "/src/editor/api.ts"; const { activeEditor } = await import(apiPath); return activeEditor()!.view.state.doc.toString(); }); 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, "one\ntwo\n"); await editorService().openFile(path); }, FILE); await openEditor(page); }); test("inoremap . .u inserts only the dot and breaks undo", async ({ page }) => { await applyRc(page, "inoremap . .u"); await page.evaluate(async () => { const apiPath = "/src/editor/api.ts"; const { activeEditor } = await import(apiPath); const view = activeEditor()!.view; view.dispatch({ selection: { anchor: 0 } }); view.focus(); }); await page.keyboard.press("i"); await page.keyboard.type("uno."); await page.keyboard.type("dos"); await expect.poll(() => documentText(page)).toBe("uno.dosone\ntwo\n"); await page.keyboard.press("Escape"); await page.keyboard.press("u"); await expect.poll(() => documentText(page)).toBe("uno.one\ntwo\n"); await page.keyboard.press("u"); await expect.poll(() => documentText(page)).toBe("one\ntwo\n"); });