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 { findNodeMatching } from "@silverbulletmd/silverbullet/lib/tree";
|
||||||
import type { LinkObject } from "../plugs/index/page_links.ts";
|
import type { LinkObject } from "../plugs/index/page_links.ts";
|
||||||
import type { Config, ConfigContainer } from "../type/config.ts";
|
import type { Config, ConfigContainer } from "../type/config.ts";
|
||||||
|
import { editor } from "@silverbulletmd/silverbullet/syscalls";
|
||||||
|
|
||||||
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
||||||
|
|
||||||
|
@ -1131,17 +1132,21 @@ export class Client implements ConfigContainer {
|
||||||
});
|
});
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
|
|
||||||
const editorState = createEditorState(
|
if (loadingDifferentPage) {
|
||||||
this,
|
const editorState = createEditorState(
|
||||||
pageName,
|
this,
|
||||||
doc.text,
|
pageName,
|
||||||
doc.meta.perm === "ro",
|
doc.text,
|
||||||
);
|
doc.meta.perm === "ro",
|
||||||
editorView.setState(editorState);
|
);
|
||||||
if (editorView.contentDOM) {
|
editorView.setState(editorState);
|
||||||
this.tweakEditorDOM(editorView.contentDOM);
|
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)
|
// Note: these events are dispatched asynchronously deliberately (not waiting for results)
|
||||||
if (loadingDifferentPage) {
|
if (loadingDifferentPage) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
unfoldAll,
|
unfoldAll,
|
||||||
unfoldCode,
|
unfoldCode,
|
||||||
} from "@codemirror/language";
|
} 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 type { Transaction } from "@codemirror/state";
|
||||||
import { EditorView } from "@codemirror/view";
|
import { EditorView } from "@codemirror/view";
|
||||||
import { getCM as vimGetCm, Vim } from "@replit/codemirror-vim";
|
import { getCM as vimGetCm, Vim } from "@replit/codemirror-vim";
|
||||||
|
@ -30,6 +30,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
||||||
const allChanges = diffAndPrepareChanges(currentText, newText);
|
const allChanges = diffAndPrepareChanges(currentText, newText);
|
||||||
client.editorView.dispatch({
|
client.editorView.dispatch({
|
||||||
changes: allChanges,
|
changes: allChanges,
|
||||||
|
annotations: isolateHistory.of("full"),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"editor.getCursor": (): number => {
|
"editor.getCursor": (): number => {
|
||||||
|
|
Loading…
Reference in New Issue