Skip to content

fix: prevent duplicated destination prefixes for template filename paths#1118

Merged
chhoumann merged 4 commits intomasterfrom
1116-bug-macros-created-notes-from-template-with-wrong-destination-paths
Feb 23, 2026
Merged

fix: prevent duplicated destination prefixes for template filename paths#1118
chhoumann merged 4 commits intomasterfrom
1116-bug-macros-created-notes-from-template-with-wrong-destination-paths

Conversation

@chhoumann
Copy link
Copy Markdown
Owner

@chhoumann chhoumann commented Feb 23, 2026

Summary

Fix template choice destination path resolution when Create in folder is disabled and File name format already includes folders.

QuickAdd was always prepending Obsidian's resolved default note folder (getNewFileParent) to the formatted filename. If the formatted name was already a vault-relative path, this produced duplicated/incorrect prefixes.

This change:

  • strips exact duplicate folder prefixes from formatted names
  • treats slash-separated formatted names as explicit vault-relative paths when their first segment exists at vault root
  • preserves existing default-folder behavior for plain filenames and relative subpaths

Closes #1116.

Before / After Repro Evidence

Before fix (confirmed)

  • Active note in 03_Aufgabenmanagement/ToDos/W-Tanso/...
  • File name format: 03_Aufgabenmanagement/ToDos/W-Work/this_is_a_task/Issue1116-before-{{DATE:YYYY-MM-DD}}.excalidraw
  • Created path:
    • 03_Aufgabenmanagement/ToDos/W-Tanso/03_Aufgabenmanagement/ToDos/W-Work/this_is_a_task/Issue1116-before-2026-02-23.excalidraw.md
  • Console log showed same duplicated destination in TemplateEngine.createFileWithTemplate.

After fix (confirmed)

Same setup now creates:

  • 03_Aufgabenmanagement/ToDos/W-Work/this_is_a_task/Issue1116-after-current-2026-02-23.excalidraw.md

With Obsidian default note location set to fixed folder (00_Journaling/Daily_Notes), same format now creates:

  • 03_Aufgabenmanagement/ToDos/W-Work/this_is_a_task/Issue1116-after-daily-2026-02-23.excalidraw.md

No runtime errors were captured via obsidian vault=dev dev:errors.

Tests

Added regression coverage in src/engine/TemplateChoiceEngine.notice.test.ts:

  • full-path filename format is treated correctly (no duplicate prefix)
  • plain filename still follows Obsidian default new-note location
  • relative subpaths remain under default location

Executed:

  • bun run test src/engine/TemplateChoiceEngine.notice.test.ts
  • bun run test
  • bun run build-with-lint

Open with Devin

Summary by CodeRabbit

  • Tests

    • Added comprehensive tests for template destination path resolution covering vault-relative paths, leading-slash and deep subpaths, plain filenames, default-folder interactions, create-in-folder behavior, and root-edge cases.
  • Bug Fixes

    • Improved template file path resolution so vault-relative names, duplicate-folder prefixes, relative subpaths, and create-in-folder scenarios produce correct destination paths.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quickadd Ready Ready Preview Feb 23, 2026 8:44pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 23, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3297d54 and 81216de.

📒 Files selected for processing (2)
  • src/engine/TemplateChoiceEngine.notice.test.ts
  • src/engine/TemplateChoiceEngine.ts

📝 Walkthrough

Walkthrough

Adds vault-relative path detection and duplicate-folder-prefix stripping to TemplateChoiceEngine path resolution; updates run flow to choose between vault-rooted and folder-scoped writes; adds comprehensive tests for many destination-path scenarios and mocks createFolder on app.vault. (34 words)

Changes

Cohort / File(s) Summary
Engine: path resolution
src/engine/TemplateChoiceEngine.ts
Introduces vault-relative handling: adds stripDuplicateFolderPrefix and shouldTreatFormattedNameAsVaultRelativePath, computes fileName/strippedPrefix, and chooses empty folder vs. computed folderPath when creating files; minor whitespace/indentation adjustments.
Tests: destination path resolution
src/engine/TemplateChoiceEngine.notice.test.ts
Adds a large test suite covering vault-relative names, leading-slash cases, duplicate-prefix stripping, default-folder behavior, create-in-folder behavior, relative subpaths and root-edge cases; adds createFolder: vi.fn() to app.vault mock and asserts createFileWithTemplate receives resolved paths.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Engine as TemplateChoiceEngine
    participant Vault
    participant TemplateSvc as TemplateService

    User->>Engine: request create with formattedName + folderPath + settings
    Engine->>Engine: stripDuplicateFolderPrefix(formattedName, folderPath)
    Engine->>Engine: shouldTreatFormattedNameAsVaultRelativePath(formattedName, strippedPrefix)
    alt treat as vault-relative
        Engine->>Vault: resolve vault-relative file path (use fileName, ignore default folder)
    else not vault-relative
        Engine->>Vault: ensure target folderPath exists (createFolder if needed)
        Vault-->>Engine: folder exists/created
        Engine->>Vault: construct full path (folderPath + fileName)
    end
    Engine->>TemplateSvc: createFileWithTemplate(resolvedPath, template, props)
    TemplateSvc->>Vault: write file at resolvedPath
    Vault-->>User: file created
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I hopped through folders, sniffed each name,
Stripped twin prefixes, solved the path-finding game.
Leading slashes point me to vault-root land,
Else I dig new folders where the settings demand.
A happy hop — no stray notes left unplanned.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: preventing duplicated destination prefixes when template filenames include folder paths.
Linked Issues check ✅ Passed The PR correctly implements the fix for issue #1116 by stripping duplicate folder prefixes, treating vault-relative paths correctly, and preserving default behavior for plain filenames.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the destination path resolution issue described in #1116; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 1116-bug-macros-created-notes-from-template-with-wrong-destination-paths

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Feb 23, 2026

Deploying quickadd with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5131b8f
Status: ✅  Deploy successful!
Preview URL: https://2a9824f1.quickadd.pages.dev
Branch Preview URL: https://1116-bug-macros-created-note.quickadd.pages.dev

View logs

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7bfd41b32f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/engine/TemplateChoiceEngine.ts Outdated
coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@chhoumann chhoumann merged commit 0a7acfe into master Feb 23, 2026
3 of 4 checks passed
@chhoumann chhoumann deleted the 1116-bug-macros-created-notes-from-template-with-wrong-destination-paths branch February 23, 2026 20:46
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 5, 2026

🎉 This PR is included in version 2.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MACROS: Created Notes from Template with wrong destination paths

1 participant