Use setText instead of replacing entire editor state (#1056)

* Fix diffAndPrepareChanges
* Use setText instead of replacing editor state
* Isolate editor.setText transaction
pull/1059/head
jcgurango 2024-08-22 03:36:50 +08:00 committed by GitHub
parent d0ed24aae5
commit eea8326220
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 11 deletions

View File

@ -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,6 +1132,7 @@ export class Client implements ConfigContainer {
});
}).catch(console.error);
if (loadingDifferentPage) {
const editorState = createEditorState(
this,
pageName,
@ -1142,6 +1144,9 @@ export class Client implements ConfigContainer {
this.tweakEditorDOM(editorView.contentDOM);
}
this.space.watchPage(pageName);
} else {
await editor.setText(doc.text);
}
// Note: these events are dispatched asynchronously deliberately (not waiting for results)
if (loadingDifferentPage) {

View File

@ -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 => {