* If the picked Template choice would have created the note at a different * path (folder settings + file name format), offer to move/rename the note * to match. Skipped when the target can't be resolved non-interactively or * already exists.
( app: App, engine: TemplateInsertEngine, choice: ITemplateChoice, file: TFile, )
| 295 | * already exists. |
| 296 | */ |
| 297 | async function maybeReconcileNoteLocation( |
| 298 | app: App, |
| 299 | engine: TemplateInsertEngine, |
| 300 | choice: ITemplateChoice, |
| 301 | file: TFile, |
| 302 | ): Promise<void> { |
| 303 | try { |
| 304 | const targetPath = await engine.computeChoiceTargetPath(choice); |
| 305 | if (!targetPath || targetPath === file.path) return; |
| 306 | if (await app.vault.adapter.exists(targetPath)) return; |
| 307 | |
| 308 | const shouldMove = await GenericYesNoPrompt.Prompt( |
| 309 | app, |
| 310 | "Move note to match choice settings?", |
| 311 | `'${choice.name}' creates notes at '${targetPath}'. Move '${file.path}' there? Links to the note will be updated.`, |
| 312 | ); |
| 313 | if (!shouldMove) return; |
| 314 | |
| 315 | const lastSlash = targetPath.lastIndexOf("/"); |
| 316 | const targetFolder = lastSlash === -1 ? "" : targetPath.slice(0, lastSlash); |
| 317 | if (targetFolder && !(await app.vault.adapter.exists(targetFolder))) { |
| 318 | await app.vault.createFolder(targetFolder); |
| 319 | } |
| 320 | |
| 321 | await app.fileManager.renameFile(file, targetPath); |
| 322 | } catch (error) { |
| 323 | if (isCancellationError(error) || isAbortError(error)) return; |
| 324 | log.logWarning(`Could not move note to match choice settings: ${error}`); |
| 325 | } |
| 326 | } |
no test coverage detected