From 44485dbeff1bb17126d9537a9d10c351ba1d6ce2 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 22 Aug 2021 09:11:33 +0200 Subject: [PATCH] feat: :sparkles: Create note if it doesn't exist Applies to all Breadcrumb links, in the trail, l/m view, visualisations, etc --- src/sharedFunctions.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index 6ceb9404..8eebba7b 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -399,7 +399,17 @@ export async function openOrSwitch( event: MouseEvent ): Promise { const { workspace } = app; - const destFile = app.metadataCache.getFirstLinkpathDest(dest, currFile.path); + let destFile = app.metadataCache.getFirstLinkpathDest(dest, currFile.path); + + if (!destFile) { + const newFileFolder = app.fileManager.getNewFileParent(currFile.path).path; + const newFilePath = `${newFileFolder}${newFileFolder === "/" ? "" : "/"}${dest}.md`; + await app.vault.create(newFilePath, ""); + destFile = app.metadataCache.getFirstLinkpathDest( + newFilePath, + currFile.path + ); + } const openLeaves: WorkspaceLeaf[] = []; // For all open leaves, if the leave's basename is equal to the link destination, rather activate that leaf instead of opening it in two panes