diff --git a/src/shared/Dialogs/Messages.ts b/src/shared/Dialogs/Messages.ts index f1bb396e..fea2cf46 100644 --- a/src/shared/Dialogs/Messages.ts +++ b/src/shared/Dialogs/Messages.ts @@ -23,6 +23,7 @@ I build this plugin as a labor of love. Curious about the philosophy behind it? - Prefer the previous experience? Turn off **Use searchable settings** at the top of Excalidraw settings and restart Obsidian. Older Obsidian versions continue using the legacy single-page layout automatically. - Settings exposed by installed Excalidraw Automate scripts have moved to **Excalidraw Automate → Settings for installed scripts** and update when a script adds or changes its settings. - Excalidraw Automate can optionally load and monitor JavaScript (\`.js\`) files in the Scripts folder, use an explicit \`.js\` startup script, and store Script Library downloads as either Markdown or JavaScript. Existing scripts can be moved between the two formats while updating startup and pinned-script paths. [#2901](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2901) +- Markdown notes created from unresolved links in a drawing now follow Obsidian's **Default location for new notes** setting. [#2916](${URLs.GITHUB_COM_ZSVICZIAN_OBSIDIAN_EXCALIDRAW_PLUGIN_ISSUES}/2916) ## New from Excalidraw.com - Improved bucket tool and eyedropper support. [#11849](${URLs.GITHUB_COM_EXCALIDRAW_EXCALIDRAW_PULL}/11849) diff --git a/src/shared/Dialogs/Prompt.ts b/src/shared/Dialogs/Prompt.ts index 17ca27d9..759bd093 100644 --- a/src/shared/Dialogs/Prompt.ts +++ b/src/shared/Dialogs/Prompt.ts @@ -5,6 +5,7 @@ import { FuzzyMatch, FuzzySuggestModal, Instruction, + normalizePath, TFile, Notice, TextAreaComponent, @@ -1096,6 +1097,7 @@ export class NewFileActions extends Modal { private openNewFile: boolean; private parentFile: TFile; private sourceElement: ExcalidrawElement; + private followObsidianNewNoteLocation: boolean; constructor({ plugin, @@ -1105,6 +1107,7 @@ export class NewFileActions extends Modal { openNewFile = true, parentFile, sourceElement, + followObsidianNewNoteLocation = false, }: { plugin: ExcalidrawPlugin; path: string; @@ -1113,6 +1116,7 @@ export class NewFileActions extends Modal { openNewFile?: boolean; parentFile?: TFile; sourceElement?: ExcalidrawElement; + followObsidianNewNoteLocation?: boolean; }) { super(plugin.app); this.plugin = plugin; @@ -1122,6 +1126,7 @@ export class NewFileActions extends Modal { this.openNewFile = openNewFile; this.sourceElement = sourceElement; this.parentFile = parentFile ?? view.file; + this.followObsidianNewNoteLocation = followObsidianNewNoteLocation; this.waitForClose = new Promise((resolve, reject) => { this.resolvePromise = resolve; this.rejectPromise = reject; @@ -1183,15 +1188,42 @@ export class NewFileActions extends Modal { return true; }; - const createFile = async (data: string): Promise => { - if (!this.path.includes("/")) { - const re = new RegExp(`${escapeRegExp(this.parentFile.name)}$`, "g"); - this.path = this.parentFile.path.replace(re, this.path); + const createFile = async ( + data: string, + useObsidianNewNoteLocation: boolean, + ): Promise => { + let path = this.path; + if (!path.match(/\.md$/)) { + path = `${path}.md`; } - if (!this.path.match(/\.md$/)) { - this.path = `${this.path}.md`; + if (!path.includes("/")) { + if ( + useObsidianNewNoteLocation && + this.followObsidianNewNoteLocation + ) { + const newFileLocation = this.app.vault.getConfig("newFileLocation"); + let targetFolder = this.parentFile.parent?.path ?? ""; + if (newFileLocation === "root") { + targetFolder = ""; + } else if (newFileLocation === "folder") { + const configuredFolder = this.app.vault.getConfig( + "newFileFolderPath", + ); + targetFolder = + typeof configuredFolder === "string" ? configuredFolder : ""; + } + path = normalizePath( + targetFolder ? `${targetFolder}/${path}` : path, + ); + } else { + const re = new RegExp( + `${escapeRegExp(this.parentFile.name)}$`, + "g", + ); + path = this.parentFile.path.replace(re, path); + } } - return await createOrOverwriteFile(this.app, this.path, data); + return await createOrOverwriteFile(this.app, path, data); }; if (this.sourceElement) { @@ -1203,7 +1235,7 @@ export class NewFileActions extends Modal { if (!checks) { return; } - const f = await createFile(""); + const f = await createFile("", true); if (f) { const ea: ExcalidrawAutomate = getEA(this.view); ea.copyViewElementsToEAforEditing([this.sourceElement]); @@ -1231,7 +1263,7 @@ export class NewFileActions extends Modal { if (!checks) { return; } - const f = await createFile(""); + const f = await createFile("", true); this.openFile(f); this.close(); }; @@ -1244,7 +1276,10 @@ export class NewFileActions extends Modal { if (!checks) { return; } - const f = await createFile(await this.plugin.getBlankDrawing()); + const f = await createFile( + await this.plugin.getBlankDrawing(), + false, + ); await sleep(200); //wait for metadata cache to update, so file opens as excalidraw this.openFile(f); this.close(); diff --git a/src/view/managers/ViewLinkNavigationManager.ts b/src/view/managers/ViewLinkNavigationManager.ts index 19de64a0..ddbc6ab7 100644 --- a/src/view/managers/ViewLinkNavigationManager.ts +++ b/src/view/managers/ViewLinkNavigationManager.ts @@ -565,6 +565,7 @@ export class ViewLinkNavigationManager { keys, view: this.view, sourceElement: el, + followObsidianNewNoteLocation: true, }).open(); return; }