1
0
silverbullet/plugs/core/editor.ts

30 lines
836 B
TypeScript
Raw Normal View History

2022-10-14 13:11:33 +00:00
import { clientStore, editor } from "$sb/silverbullet-syscall/mod.ts";
2022-09-16 12:26:47 +00:00
export async function editorLoad() {
2022-10-14 13:11:33 +00:00
const readOnlyMode = await clientStore.get("readOnlyMode");
2022-09-16 12:26:47 +00:00
if (readOnlyMode) {
2022-10-14 13:11:33 +00:00
await editor.enableReadOnlyMode(true);
2022-09-16 12:26:47 +00:00
}
}
export async function toggleReadOnlyMode() {
let readOnlyMode = await clientStore.get("readOnlyMode");
readOnlyMode = !readOnlyMode;
2022-10-14 13:11:33 +00:00
await editor.enableReadOnlyMode(readOnlyMode);
2022-09-16 12:26:47 +00:00
await clientStore.set("readOnlyMode", readOnlyMode);
}
2022-12-16 11:44:04 +00:00
// Run on "editor:init"
export async function setEditorMode() {
if (await clientStore.get("vimMode")) {
await editor.setVimEnabled(true);
}
}
export async function toggleVimMode() {
let vimMode = await clientStore.get("vimMode");
vimMode = !vimMode;
await editor.setVimEnabled(vimMode);
await clientStore.set("vimMode", vimMode);
}