1
0
silverbullet/plugs/core/editor.ts

45 lines
1.0 KiB
TypeScript
Raw Normal View History

import { editor } from "$sb/silverbullet-syscall/mod.ts";
import { store } from "$sb/plugos-syscall/mod.ts";
2022-09-16 12:26:47 +00:00
2022-12-16 11:44:04 +00:00
// Run on "editor:init"
export async function setEditorMode() {
if (await store.get("vimMode")) {
await editor.setUiOption("vimMode", true);
}
if (await store.get("darkMode")) {
await editor.setUiOption("darkMode", true);
2022-12-16 11:44:04 +00:00
}
}
export async function toggleDarkMode() {
let darkMode = await store.get("darkMode");
darkMode = !darkMode;
await editor.setUiOption("darkMode", darkMode);
await store.set("darkMode", darkMode);
}
2023-06-14 17:27:18 +00:00
export async function foldCommand() {
await editor.fold();
}
export async function unfoldCommand() {
await editor.unfold();
}
2023-06-17 07:01:32 +00:00
export async function toggleFoldCommand() {
await editor.toggleFold();
}
2023-06-14 17:27:18 +00:00
export async function foldAllCommand() {
await editor.foldAll();
}
export async function unfoldAllCommand() {
await editor.unfoldAll();
}
2023-07-24 09:27:46 +00:00
export async function centerCursorCommand() {
const pos = await editor.getCursor();
await editor.moveCursor(pos, true);
}