2023-05-23 18:53:53 +00:00
|
|
|
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() {
|
2023-05-23 18:53:53 +00:00
|
|
|
if (await store.get("vimMode")) {
|
2022-12-21 13:55:24 +00:00
|
|
|
await editor.setUiOption("vimMode", true);
|
|
|
|
}
|
2023-05-23 18:53:53 +00:00
|
|
|
if (await store.get("darkMode")) {
|
2022-12-21 13:55:24 +00:00
|
|
|
await editor.setUiOption("darkMode", true);
|
2022-12-16 11:44:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-21 13:55:24 +00:00
|
|
|
export async function toggleDarkMode() {
|
2023-05-23 18:53:53 +00:00
|
|
|
let darkMode = await store.get("darkMode");
|
2022-12-21 13:55:24 +00:00
|
|
|
darkMode = !darkMode;
|
|
|
|
await editor.setUiOption("darkMode", darkMode);
|
2023-05-23 18:53:53 +00:00
|
|
|
await store.set("darkMode", darkMode);
|
2022-12-21 13:55:24 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
2023-07-27 15:02:53 +00:00
|
|
|
|
|
|
|
export async function moveToPosCommand() {
|
|
|
|
const posString = await editor.prompt("Move to position:");
|
|
|
|
if (!posString) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const pos = +posString;
|
|
|
|
await editor.moveCursor(pos);
|
|
|
|
}
|