M1.6: tabs and CodeMirror editor
- Editor area with tab bar, CodeMirror 6 view, close question and notices (ui/src/components/editor/, ui/src/stores/editor.ts), mounted in App.vue; the project tree opens files through the editor store. - BufferSync: local edits to buffer.edit against the confirmed version, one call in flight, resync on stale_version or newer bufferChanged with rebase of unsent changes; EngineText maps CodeMirror positions to engine UTF-16 offsets for CRLF text. - Save, save all and close from engine default shortcuts via listCommands. - Dirty marker, Save / Don't Save / Cancel, non-blocking notice when a dirty file changes or disappears on disk. - Vitest: keystroke bursts with stale versions and remote edits (LF and CRLF), mapping, store and component tests against a fake engine. - Progress docs: Editor core 8% (est.), depth ~1.4%, G2, ui-parity tabs, M1 row, architecture, README status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0fb7e33fc7
commit
9fa6028335
25 changed files with 2958 additions and 22 deletions
58
ui/tests/editor/engineText.test.ts
Normal file
58
ui/tests/editor/engineText.test.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Tests for the mapping between engine text (line breaks as on disk) and
|
||||
* CodeMirror documents (one position per line break).
|
||||
*/
|
||||
import { ChangeSet, Text } from "@codemirror/state";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { diffDocs, EngineText, separatorOf } from "../../src/components/editor/engineText";
|
||||
|
||||
describe("EngineText", () => {
|
||||
it("maps positions past CRLF breaks and keeps mixed endings", () => {
|
||||
const text = EngineText.fromEngine("a\r\nb\nc\rd\r\n");
|
||||
expect(text.doc.toString()).toBe("a\nb\nc\nd\n");
|
||||
expect(text.toEngine(0)).toBe(0);
|
||||
expect(text.toEngine(2)).toBe(3);
|
||||
expect(text.toEngine(4)).toBe(5);
|
||||
expect(text.toEngine(8)).toBe(10);
|
||||
expect(text.toEngine(99)).toBe(10);
|
||||
expect(text.engineString()).toBe("a\r\nb\nc\nd\r\n");
|
||||
});
|
||||
|
||||
it("is the identity for text without CRLF", () => {
|
||||
const text = EngineText.fromEngine("x😀\ny");
|
||||
expect(text.toEngine(4)).toBe(4);
|
||||
});
|
||||
|
||||
it("turns changes into engine edits with the buffer's line ending", () => {
|
||||
const text = EngineText.fromEngine("ab\r\ncd\r\n");
|
||||
const changes = ChangeSet.of(
|
||||
[
|
||||
{ from: 1, insert: "\n" },
|
||||
{ from: 3, to: 5, insert: "X" },
|
||||
],
|
||||
text.doc.length,
|
||||
);
|
||||
expect(text.edits(changes, "\r\n")).toEqual([
|
||||
{ from: 1, to: 1, insert: "\r\n" },
|
||||
{ from: 4, to: 6, insert: "X" },
|
||||
]);
|
||||
const after = text.apply(changes, "\r\n");
|
||||
expect(after.doc.toString()).toBe("a\nb\nX\n");
|
||||
expect(after.engineString()).toBe("a\r\nb\r\nX\r\n");
|
||||
});
|
||||
|
||||
it("diffs documents into one replacement", () => {
|
||||
const a = Text.of(["hello", "world"]);
|
||||
const b = Text.of(["hello", "brave", "world"]);
|
||||
const diff = diffDocs(a, b);
|
||||
expect(diff.apply(a).toString()).toBe(b.toString());
|
||||
expect(diffDocs(a, a).empty).toBe(true);
|
||||
});
|
||||
|
||||
it("names separators", () => {
|
||||
expect(separatorOf("crlf")).toBe("\r\n");
|
||||
expect(separatorOf("cr")).toBe("\r");
|
||||
expect(separatorOf("lf")).toBe("\n");
|
||||
expect(separatorOf("?")).toBe("\n");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue