MCPcopy Create free account
hub / github.com/chhoumann/quickadd / maybeReconcileNoteLocation

Function maybeReconcileNoteLocation

src/engine/applyTemplateToActiveNote.ts:297–326  ·  view source on GitHub ↗

* 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,
)

Source from the content-addressed store, hash-verified

295 * already exists.
296 */
297async 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}

Callers 1

applyTemplateToNoteFunction · 0.85

Calls 5

isCancellationErrorFunction · 0.90
isAbortErrorFunction · 0.70
logWarningMethod · 0.65
PromptMethod · 0.45

Tested by

no test coverage detected