From 8fbf999df4b6d3a7b82377f1686732b045490553 Mon Sep 17 00:00:00 2001 From: Paul <70213368+LostPaul@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:56:52 +0100 Subject: [PATCH] Fix #304 --- src/functions/excalidraw.ts | 16 +++++++++++++--- src/functions/folderNoteFunctions.ts | 23 ++++------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/functions/excalidraw.ts b/src/functions/excalidraw.ts index 8b0286e..b0cebc0 100644 --- a/src/functions/excalidraw.ts +++ b/src/functions/excalidraw.ts @@ -1,19 +1,29 @@ -import type { WorkspaceLeaf, App } from 'obsidian'; +import type { WorkspaceLeaf, App, TFile } from 'obsidian'; interface ExcalidrawPlugin { setExcalidrawView(leaf: WorkspaceLeaf): void; + openDrawing(file: TFile): void; + getBlankDrawing(): Promise; } export async function openExcalidrawView( app: App, - leaf: WorkspaceLeaf, + file: TFile, ): Promise { const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(app); if (excalidrawEnabled && excalidraw) { - excalidraw.setExcalidrawView(leaf); + excalidraw.openDrawing(file); } } +export async function getDefaultTemplate(app: App): Promise { + const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(app); + if (excalidrawEnabled && excalidraw) { + return excalidraw.getBlankDrawing(); + } + return ''; +} + export async function getExcalidrawPlugin( app: App, ): Promise<{ excalidraw: ExcalidrawPlugin | null; excalidrawEnabled: boolean }> { diff --git a/src/functions/folderNoteFunctions.ts b/src/functions/folderNoteFunctions.ts index e91d750..012674b 100644 --- a/src/functions/folderNoteFunctions.ts +++ b/src/functions/folderNoteFunctions.ts @@ -20,7 +20,7 @@ import { updateExcludedFolder, } from '../ExcludeFolders/functions/folderFunctions'; import { ExcludedFolder } from '../ExcludeFolders/ExcludeFolder'; -import { openExcalidrawView } from './excalidraw'; +import { getDefaultTemplate, openExcalidrawView } from './excalidraw'; import { AskForExtensionModal } from 'src/modals/AskForExtension'; import { addCSSClassToFileExplorerEl, @@ -35,21 +35,6 @@ import { } from 'src/functions/utils'; -const defaultExcalidrawTemplate = `--- - -excalidraw-plugin: parsed -tags: [excalidraw] - ---- -==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠== - - -%% -# Drawing -\`\`\`json -{'type":"excalidraw","version":2,"source":"https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.9.20","elements":[],"appState":{"gridSize":null,"viewBackgroundColor":"#ffffff'}} -\`\`\` -%%`; export async function createFolderNote( plugin: FolderNotesPlugin, @@ -121,7 +106,7 @@ export async function createFolderNote( } await leaf.openFile(folderNote); if (plugin.settings.folderNoteType === '.excalidraw' || extension === '.excalidraw') { - openExcalidrawView(plugin.app, leaf); + openExcalidrawView(plugin.app, folderNote); } } @@ -192,7 +177,7 @@ async function handleCreateFolderNote(plugin: FolderNotesPlugin, folderNoteType: '==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==', ) ) { - content = defaultExcalidrawTemplate; + content = await getDefaultTemplate(plugin.app); } } else { plugin.app.vault.readBinary(templateFile).then(async (data) => { @@ -208,7 +193,7 @@ async function handleCreateFolderNote(plugin: FolderNotesPlugin, folderNoteType: plugin.settings.folderNoteType === '.excalidraw' || extension === '.excalidraw' ) { - content = defaultExcalidrawTemplate; + content = await getDefaultTemplate(plugin.app); } else if (plugin.settings.folderNoteType === '.canvas') { content = '{}'; }