Файли
openidea/e2e/vimLineNumbers.spec.ts
T
l0ng-ai a372385788 feat(vim): apply number and relativenumber from the rc file to the line numbers (#7381)
set relativenumber in ~/.ideavimrc was reported as an unsupported option and the gutter kept absolute numbers. As in IdeaVim, number (nu) and relativenumber (rnu) now set every editor's line numbers over Settings › Editor › General › Appearance › Show line numbers: both on is hybrid, relativenumber alone shows 0 on the caret line, both off hides them. An option the rc file leaves alone reads and follows Settings, nothing is written back, and turning Vim mode off or reloading an rc file without them returns to Settings. The options live in an editor-core store that lineNumbersExtension reads; the controller re-applies settings when it changes, as for Distraction Free Mode.

Fixes #7341
2026-12-02 12:53:37 +08:00

59 рядки
2.5 KiB
TypeScript

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");
});