diff --git a/web/client.ts b/web/client.ts index 355b2ef2..6d91e7e6 100644 --- a/web/client.ts +++ b/web/client.ts @@ -75,6 +75,7 @@ import { lezerToParseTree } from "$common/markdown_parser/parse_tree.ts"; import { findNodeMatching } from "@silverbulletmd/silverbullet/lib/tree"; import type { LinkObject } from "../plugs/index/page_links.ts"; import type { Config, ConfigContainer } from "../type/config.ts"; +import { editor } from "@silverbulletmd/silverbullet/syscalls"; const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/; @@ -1131,17 +1132,21 @@ export class Client implements ConfigContainer { }); }).catch(console.error); - const editorState = createEditorState( - this, - pageName, - doc.text, - doc.meta.perm === "ro", - ); - editorView.setState(editorState); - if (editorView.contentDOM) { - this.tweakEditorDOM(editorView.contentDOM); + if (loadingDifferentPage) { + const editorState = createEditorState( + this, + pageName, + doc.text, + doc.meta.perm === "ro", + ); + editorView.setState(editorState); + if (editorView.contentDOM) { + this.tweakEditorDOM(editorView.contentDOM); + } + this.space.watchPage(pageName); + } else { + await editor.setText(doc.text); } - this.space.watchPage(pageName); // Note: these events are dispatched asynchronously deliberately (not waiting for results) if (loadingDifferentPage) { diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index be5af5a9..d7701360 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -6,7 +6,7 @@ import { unfoldAll, unfoldCode, } from "@codemirror/language"; -import { deleteLine, redo, undo } from "@codemirror/commands"; +import { deleteLine, isolateHistory, redo, undo } from "@codemirror/commands"; import type { Transaction } from "@codemirror/state"; import { EditorView } from "@codemirror/view"; import { getCM as vimGetCm, Vim } from "@replit/codemirror-vim"; @@ -30,6 +30,7 @@ export function editorSyscalls(client: Client): SysCallMapping { const allChanges = diffAndPrepareChanges(currentText, newText); client.editorView.dispatch({ changes: allChanges, + annotations: isolateHistory.of("full"), }); }, "editor.getCursor": (): number => {