import { expect, stubDesktop, test } from "./fixtures"; const FILE = "/dev/acme-api/line-numbers.txt"; /** Applies rc file lines through the same parser and engine the app uses. */ async function applyRc(page: import("@playwright/test").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); } test("set relativenumber in the rc file switches the editor's line numbers (#7341)", 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, "a\nb\nc\nd\ne\n"); await editorService().openFile(path); }, FILE); const editor = page.locator(".cm-editor").first(); await expect(editor).toHaveAttribute("data-openidea-vim", "true"); const numbers = editor.locator(".cm-lineNumbers .cm-gutterElement:not([style*='visibility: hidden'])"); await editor.locator(".cm-content").click(); await page.keyboard.press("g"); await page.keyboard.press("g"); await page.keyboard.press("j"); await page.keyboard.press("j"); await expect(numbers.filter({ hasText: /^\d+$/ }).first()).toBeVisible(); // `number` follows Settings (absolute numbers on): hybrid, the caret line keeps its number. await applyRc(page, "set relativenumber"); await expect(numbers.nth(0)).toHaveText("2"); await expect(numbers.nth(2)).toHaveText("3"); await expect(numbers.nth(3)).toHaveText("1"); await applyRc(page, "set nonumber relativenumber"); await expect(numbers.nth(2)).toHaveText("0"); await applyRc(page, "set nonu nornu"); await expect(editor.locator(".cm-lineNumbers")).toHaveCount(0); await applyRc(page, ""); await expect(numbers.nth(0)).toHaveText("1"); await expect(numbers.nth(2)).toHaveText("3"); });