From 5b620b2dcc1f0155f4cfcb2cd4fd49e0cd8c1bb2 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 12 Jul 2023 11:00:25 +0200 Subject: [PATCH] Fixes snippets not working in unsaved page --- plugs/core/template.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugs/core/template.ts b/plugs/core/template.ts index bf712c7..b3d4d42 100644 --- a/plugs/core/template.ts +++ b/plugs/core/template.ts @@ -221,7 +221,17 @@ export async function weeklyNoteCommand() { export async function insertTemplateText(cmdDef: any) { const cursorPos = await editor.getCursor(); const page = await editor.getCurrentPage(); - const pageMeta = await space.getPageMeta(page); + let pageMeta: PageMeta | undefined; + try { + pageMeta = await space.getPageMeta(page); + } catch { + // Likely page not yet created + pageMeta = { + name: page, + lastModified: -1, + perm: "rw", + }; + } let templateText: string = cmdDef.value; const carretPos = templateText.indexOf("|^|"); templateText = templateText.replace("|^|", "");