Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"license": "MIT",
"dependencies": {
"@codemirror/commands": "6.10.2",
"@codemirror/lang-markdown": "^6.5.0",
"@codemirror/language": "^6.12.2",
"@codemirror/state": "^6.5.2",
Expand All @@ -31,6 +32,11 @@
"@xterm/xterm": "^6.0.0",
"mermaid": "^11.13.0"
},
"pnpm": {
"overrides": {
"@codemirror/state": "6.5.4"
}
},
"devDependencies": {
"@playwright/test": "^1.58.2",
"@sveltejs/vite-plugin-svelte": "^5.0.0",
Expand Down
10 changes: 8 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/lib/CodeMirrorNoteEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { untrack } from "svelte";
import { EditorState } from "@codemirror/state";
import { EditorView, drawSelection } from "@codemirror/view";
import { history } from "@codemirror/commands";
import { markdown } from "@codemirror/lang-markdown";
import { Vim, getCM, vim } from "@replit/codemirror-vim";
import { markdownLivePreview } from "./markdownLivePreview";
Expand Down Expand Up @@ -95,6 +96,7 @@
doc,
extensions: [
vim(),
history(),
drawSelection(),
markdown(),
markdownLivePreview({ resolveImageSrc: untrack(() => resolveImageSrc) }),
Expand Down
40 changes: 40 additions & 0 deletions src/lib/NotesEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,46 @@ describe("NotesEditor", () => {
expect(get(focusTarget)).toEqual({ type: "note", filename: "a.md", folder: "Project Alpha" });
});

it("supports vim undo (u) to revert typed text", async () => {
vi.mocked(command).mockImplementation((commandName: string) => {
if (commandName === "read_note") {
return Promise.resolve("original");
}

if (commandName === "write_note") {
return Promise.resolve(undefined);
}

return Promise.resolve(undefined);
});

focusTarget.set({ type: "notes-editor", folder: "Project Alpha" });

render(NotesEditor);
const user = userEvent.setup();

const editor = await screen.findByTestId("note-code-editor");
const textbox = within(editor).getByRole("textbox");
textbox.focus();

// Enter insert mode, type text, return to normal mode
await user.keyboard("A"); // append at end of line
await user.keyboard(" added");
await user.keyboard("{Escape}");

await waitFor(() => {
expect(editor).toHaveTextContent("original added");
});

// Press 'u' to undo
await user.keyboard("u");

await waitFor(() => {
expect(editor).toHaveTextContent("original");
expect(editor).not.toHaveTextContent("original added");
});
});

it("keeps the latest note content when read_note resolves out of order", async () => {
const noteARequest = deferred<string>();
const noteBRequest = deferred<string>();
Expand Down
Loading