Files
openidea/src/editor/core/model/documentLanguage.test.ts
T
kkmihaiandkkMihai 239753df9f fix(editor): speed up rapid file opening (#734)
Rapid double-clicks queued their opens one after another and an earlier open finishing late took the active tab and focus back. Each open now carries a sequence/activation generation: only the newest request activates and focuses, older ones still add their tab. Pending file probes are shared, document and syntax loading overlap, and repeated folder double-clicks are handled. A pending navigation selection survives a later plain open of any file; a newer selection still wins. Refs #724.

Co-authored-by: kkMihai <59262001+kkMihai@users.noreply.github.com>
2026-11-02 10:38:02 +08:00

57 lines
1.8 KiB
TypeScript

import { expect, it, vi } from "vitest";
import { language as languageFacet } from "@codemirror/language";
import { createMemoryBackend } from "../backend";
import { DocumentManager } from "./document";
import { EditorSlot } from "./slot";
const loading = vi.hoisted(() => {
let finish!: () => void;
const ready = new Promise<void>((resolve) => {
finish = resolve;
});
return { ready, finish, started: false, modes: [] as string[] };
});
vi.mock("../cm/languages", async (importOriginal) => {
const actual = await importOriginal<typeof import("../cm/languages")>();
return {
...actual,
loadSupport: async (...args: Parameters<typeof actual.loadSupport>) => {
loading.started = true;
loading.modes.push(args[0].name);
await loading.ready;
return actual.loadSupport(...args);
},
};
});
it("waits for the lazy mode before exposing an Angular document to its first slot", async () => {
const manager = new DocumentManager(
createMemoryBackend({ "/p/angular.json": "{}", "/p/src/app.html": "<p>{{ name }}</p>" }),
{ settings: () => ({}), notify: vi.fn() },
);
let acquired = false;
const pending = manager.acquire("/p/src/app.html").then((model) => {
acquired = true;
return model;
});
await vi.waitFor(() => expect(loading.started).toBe(true));
try {
expect(acquired).toBe(false);
} finally {
loading.finish();
}
const model = await pending;
const slot = new EditorSlot(model, "t1", {
onFocus() {},
onBlur() {},
onSelection() {},
onUserEdit() {},
onContextMenu() {},
});
expect(slot.currentState().facet(languageFacet)?.name).toBe("angular");
expect(loading.modes).toEqual(expect.arrayContaining(["HTML", "Angular Template"]));
slot.dispose();
manager.stop();
});