M2.2: PHP highlighting, syntax colour tokens and editor.reveal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-17 12:06:42 +02:00
parent f13a49064d
commit 6c75c08d70
25 changed files with 1044 additions and 33 deletions

View file

@ -4,7 +4,7 @@
*/
import { ChangeSet, Text } from "@codemirror/state";
import { describe, expect, it } from "vitest";
import { diffDocs, EngineText, separatorOf } from "../../src/components/editor/engineText";
import { diffDocs, EngineText, positionOf, separatorOf } from "../../src/components/editor/engineText";
describe("EngineText", () => {
it("maps positions past CRLF breaks and keeps mixed endings", () => {
@ -56,3 +56,26 @@ describe("EngineText", () => {
expect(separatorOf("?")).toBe("\n");
});
});
describe("positionOf", () => {
it("maps engine line and UTF-16 column to the same text in CRLF and LF documents", () => {
for (const engine of ["ab\r\ncd😀e\r\n\r\nf", "ab\ncd😀e\n\nf", "ab\rcd😀e\r\rf"]) {
const text = EngineText.fromEngine(engine);
const pos = positionOf(text.doc, 1, 4);
expect(text.doc.sliceString(pos, pos + 1)).toBe("e");
expect(engine.charAt(text.toEngine(pos))).toBe("e");
const f = positionOf(text.doc, 3, 0);
expect(engine.charAt(text.toEngine(f))).toBe("f");
}
});
it("clamps lines and columns into the document", () => {
const doc = EngineText.fromEngine("ab\r\ncd").doc;
expect(positionOf(doc, 0, 99)).toBe(2);
expect(positionOf(doc, 99, 1)).toBe(4);
expect(positionOf(doc, -3, -1)).toBe(0);
expect(positionOf(doc, 1.8, 1.9)).toBe(4);
expect(positionOf(doc, Number.NaN, Number.POSITIVE_INFINITY)).toBe(0);
expect(positionOf(Text.empty, 4, 4)).toBe(0);
});
});