2022-10-14 13:11:33 +00:00
|
|
|
import { clientStore, editor, system } from "$sb/silverbullet-syscall/mod.ts";
|
|
|
|
import { readSettings } from "$sb/lib/settings_page.ts";
|
2022-03-28 13:25:05 +00:00
|
|
|
|
2022-04-04 13:25:07 +00:00
|
|
|
export async function togglePreview() {
|
2022-10-14 13:11:33 +00:00
|
|
|
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
|
2022-04-04 13:25:07 +00:00
|
|
|
await clientStore.set("enableMarkdownPreview", !currentValue);
|
|
|
|
if (!currentValue) {
|
2022-10-14 13:11:33 +00:00
|
|
|
await system.invokeFunction("client", "preview");
|
2022-04-04 13:25:07 +00:00
|
|
|
} else {
|
2022-04-13 12:46:52 +00:00
|
|
|
await hideMarkdownPreview();
|
2022-04-09 12:57:59 +00:00
|
|
|
}
|
2022-03-28 13:25:05 +00:00
|
|
|
}
|
2022-04-04 13:25:07 +00:00
|
|
|
|
|
|
|
async function hideMarkdownPreview() {
|
2022-10-10 12:50:21 +00:00
|
|
|
const setting = await readSettings({ previewOnRHS: true });
|
2022-10-14 13:53:51 +00:00
|
|
|
await editor.hidePanel(setting.previewOnRHS ? "rhs" : "lhs");
|
2022-04-04 13:25:07 +00:00
|
|
|
}
|