2022-07-24 01:18:03 +08:00
|
|
|
import { hideRhs, hideLhs } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
2022-04-25 17:24:13 +08:00
|
|
|
import { invokeFunction } from "@silverbulletmd/plugos-silverbullet-syscall/system";
|
|
|
|
import * as clientStore from "@silverbulletmd/plugos-silverbullet-syscall/clientStore";
|
2022-07-24 01:18:03 +08:00
|
|
|
import { readSettings, writeSettings } from "@silverbulletmd/plugs/lib/settings_page";;
|
|
|
|
|
2022-03-28 21:25:05 +08:00
|
|
|
|
2022-04-04 21:25:07 +08:00
|
|
|
export async function togglePreview() {
|
|
|
|
let currentValue = !!(await clientStore.get("enableMarkdownPreview"));
|
|
|
|
await clientStore.set("enableMarkdownPreview", !currentValue);
|
|
|
|
if (!currentValue) {
|
2022-04-13 20:46:52 +08:00
|
|
|
await invokeFunction("client", "preview");
|
2022-04-04 21:25:07 +08:00
|
|
|
} else {
|
2022-04-13 20:46:52 +08:00
|
|
|
await hideMarkdownPreview();
|
2022-04-09 20:57:59 +08:00
|
|
|
}
|
2022-03-28 21:25:05 +08:00
|
|
|
}
|
2022-04-04 21:25:07 +08:00
|
|
|
|
|
|
|
async function hideMarkdownPreview() {
|
2022-07-24 01:18:03 +08:00
|
|
|
const setting = await readSettings({previewOnRHS: true});
|
|
|
|
const hide = setting.previewOnRHS ? hideRhs : hideLhs;
|
|
|
|
await hide();
|
2022-04-04 21:25:07 +08:00
|
|
|
}
|