Remove `editor.setText` syscall from client (#1263)
parent
6fe715518f
commit
a6af94b9e3
|
@ -5,6 +5,7 @@ import type {
|
|||
import type { Compartment, EditorState } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { indentUnit, syntaxTree } from "@codemirror/language";
|
||||
import { isolateHistory } from "@codemirror/commands";
|
||||
import { compile as gitIgnoreCompiler } from "gitignore-parser";
|
||||
import type { SyntaxNode } from "@lezer/common";
|
||||
import { Space } from "../common/space.ts";
|
||||
|
@ -74,7 +75,7 @@ import { lezerToParseTree } from "$common/markdown_parser/parse_tree.ts";
|
|||
import { findNodeMatching } from "@silverbulletmd/silverbullet/lib/tree";
|
||||
import type { AspiringPageObject } from "../plugs/index/page_links.ts";
|
||||
import type { Config, ConfigContainer } from "../type/config.ts";
|
||||
import { editor } from "@silverbulletmd/silverbullet/syscalls";
|
||||
import { diffAndPrepareChanges } from "./cm_util.ts";
|
||||
|
||||
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
|
||||
|
||||
|
@ -1157,7 +1158,7 @@ export class Client implements ConfigContainer {
|
|||
this.space.watchPage(pageName);
|
||||
} else {
|
||||
// Just apply minimal patches so that the cursor is preserved
|
||||
await editor.setText(doc.text, true);
|
||||
this.setEditorText(doc.text, true);
|
||||
}
|
||||
|
||||
// Note: these events are dispatched asynchronously deliberately (not waiting for results)
|
||||
|
@ -1190,6 +1191,15 @@ export class Client implements ConfigContainer {
|
|||
contentDOM.setAttribute("autocapitalize", "on");
|
||||
}
|
||||
|
||||
setEditorText(newText: string, shouldIsolateHistory = false) {
|
||||
const currentText = this.editorView.state.sliceDoc();
|
||||
const allChanges = diffAndPrepareChanges(currentText, newText);
|
||||
client.editorView.dispatch({
|
||||
changes: allChanges,
|
||||
annotations: shouldIsolateHistory ? isolateHistory.of("full") : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async loadCustomStyles() {
|
||||
const spaceStyles = await this.clientSystem.queryObjects<StyleObject>(
|
||||
"space-style",
|
||||
|
|
|
@ -8,7 +8,6 @@ import {
|
|||
} from "@codemirror/language";
|
||||
import {
|
||||
deleteLine,
|
||||
isolateHistory,
|
||||
moveLineDown,
|
||||
moveLineUp,
|
||||
redo,
|
||||
|
@ -22,7 +21,6 @@ import type { FilterOption } from "@silverbulletmd/silverbullet/type/client";
|
|||
import type { PageMeta, UploadFile } from "../../plug-api/types.ts";
|
||||
import type { PageRef } from "@silverbulletmd/silverbullet/lib/page_ref";
|
||||
import { openSearchPanel } from "@codemirror/search";
|
||||
import { diffAndPrepareChanges } from "../cm_util.ts";
|
||||
|
||||
export function editorSyscalls(client: Client): SysCallMapping {
|
||||
const syscalls: SysCallMapping = {
|
||||
|
@ -36,14 +34,7 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|||
return client.editorView.state.sliceDoc();
|
||||
},
|
||||
"editor.setText": (_ctx, newText: string, shouldIsolateHistory = false) => {
|
||||
const currentText = client.editorView.state.sliceDoc();
|
||||
const allChanges = diffAndPrepareChanges(currentText, newText);
|
||||
client.editorView.dispatch({
|
||||
changes: allChanges,
|
||||
annotations: shouldIsolateHistory
|
||||
? isolateHistory.of("full")
|
||||
: undefined,
|
||||
});
|
||||
client.setEditorText(newText, shouldIsolateHistory);
|
||||
},
|
||||
"editor.getCursor": (): number => {
|
||||
return client.editorView.state.selection.main.from;
|
||||
|
|
Loading…
Reference in New Issue