Use the authenticated navigation logo to open the existing focus-mode editor and preserve the draft cursor across reopenings.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { EditorState } from "@codemirror/state";
|
|
import { EditorView } from "@codemirror/view";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createController } from "@/components/MemoEditor/Editor/controller";
|
|
|
|
function view(doc = "") {
|
|
return new EditorView({ state: EditorState.create({ doc }) });
|
|
}
|
|
|
|
describe("source editor controller", () => {
|
|
it("round-trips markdown verbatim, including previously-lossy inputs", () => {
|
|
const v = view();
|
|
const c = createController(v, {} as never);
|
|
for (const md of ["", "Title\n===", "1. a\n 1. b\n 1. c", "a b"]) {
|
|
c.setMarkdown(md);
|
|
expect(c.getMarkdown()).toBe(md);
|
|
}
|
|
});
|
|
|
|
it("reports emptiness on whitespace", () => {
|
|
const c = createController(view(" \n "), {} as never);
|
|
expect(c.isEmpty()).toBe(true);
|
|
});
|
|
|
|
it("inserts markdown as its own block", () => {
|
|
const v = view("alpha");
|
|
const c = createController(v, {} as never);
|
|
v.dispatch({ selection: { anchor: 5 } });
|
|
c.insertMarkdown("beta");
|
|
expect(c.getMarkdown()).toBe("alpha\n\nbeta");
|
|
});
|
|
|
|
it("captures and restores the cursor", () => {
|
|
const v = view("alpha beta");
|
|
const c = createController(v, {} as never);
|
|
v.dispatch({ selection: { anchor: 7 } });
|
|
|
|
expect(c.getCursor()).toBe(7);
|
|
|
|
c.setCursor(99);
|
|
expect(c.getCursor()).toBe(10);
|
|
});
|
|
});
|