Use setText instead of replacing entire editor state (#1056)
* Fix diffAndPrepareChanges * Use setText instead of replacing editor state * Isolate editor.setText transactionpull/1059/head
parent
d0ed24aae5
commit
eea8326220
|
@ -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) {
|
||||
|
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in New Issue