дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
An Insert-mode mapping such as `inoremap . .<C-g>u` typed the literal text ".<C-g>u": codemirror-vim has no <C-g>u command and writes unknown <...> keys of a mapping's right-hand side into the document. inoremap only searches the engine's built-in keymap, so the key is added there through a patch to @replit/codemirror-vim-core, bound to an action that isolates the next history event so the text after it starts a new undo group. Covered by a Vim engine unit test and e2e/vimUndoBreak.spec.ts. Co-authored-by: angelf015 <[email protected]>
73 рядки
2.7 KiB
TypeScript
73 рядки
2.7 KiB
TypeScript
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 . .<C-g>u inserts only the dot and breaks undo", async ({ page }) => {
|
|
await applyRc(page, "inoremap . .<C-g>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");
|
|
});
|