2023-05-23 18:53:53 +00:00
|
|
|
import { editor } from "$sb/silverbullet-syscall/mod.ts";
|
2022-10-14 13:11:33 +00:00
|
|
|
import { readSettings } from "$sb/lib/settings_page.ts";
|
2023-05-23 18:53:53 +00:00
|
|
|
import { updateMarkdownPreview } from "./preview.ts";
|
2023-08-26 06:31:51 +00:00
|
|
|
import { clientStore } from "$sb/silverbullet-syscall/mod.ts";
|
2022-03-28 13:25:05 +00:00
|
|
|
|
2022-04-04 13:25:07 +00:00
|
|
|
export async function togglePreview() {
|
2023-08-26 06:31:51 +00:00
|
|
|
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
|
|
|
|
await clientStore.set("enableMarkdownPreview", !currentValue);
|
2022-04-04 13:25:07 +00:00
|
|
|
if (!currentValue) {
|
2023-05-23 18:53:53 +00:00
|
|
|
await updateMarkdownPreview();
|
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
|
|
|
}
|