Skip to content

Apply a template to an existing note#721

Merged
h4yfans merged 17 commits into
mainfrom
note-template-apply
Jul 9, 2026
Merged

Apply a template to an existing note#721
h4yfans merged 17 commits into
mainfrom
note-template-apply

Conversation

@h4yfans

@h4yfans h4yfans commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Apply a template to an existing note

Templates previously only applied at note creation, folder-default, and journal-default. This adds the ability to apply a template to an existing individual note from two entry points.

Behavior

  • Entry points: right-click a note in the sidebar tree → Apply Template, or the note-page ⋮ (more) menu → Apply Template. Works in both the virtualized and legacy tree render paths.
  • Empty note: applies immediately.
  • Note with content: confirmation dialog with two choices:
    • Replace content & add template details — replaces the body and merges the template's tags/properties (non-destructive: existing tags kept via union; on a property-key conflict the note's existing value wins).
    • Replace content only — replaces the body, leaves tags/properties untouched.
  • {{title}} resolves to the note's current title.
  • If the note's editor is open, its content updates live.

Implementation

  • Additive IPC method notes:apply-template ({ noteId, templateId, mode: 'full' | 'body' }) → contract + rpc + handler.
  • Main command applyTemplateToNote: pure buildTemplateApplyUpdate (tag union, existing-wins property merge, {{title}}), reuses updateNoteCommand (file + index + sync), then feeds the open editor's Y.Doc.
  • Extracted replaceNoteBodyInCrdt from the vault watcher into a shared crdt-feed module so external-edit and template-apply share one fragment-replace path.
  • Renderer: TemplateSelector gains an apply mode; new confirmation dialog; a self-contained orchestrator dialog mounted at both entry points (inert while closed).

Notes

  • Backward compatible: no DB schema, sync-protocol, vault file-format, or settings changes — additive IPC only.
  • Full-mode apply on an open, tag-bearing note also syncs the live Y.Doc tag array, so the CRDT writeback can't revert the template's added tags on the next body edit.
  • Docs updated under apps/docs/src/user-guide/templates.md.

Verification

  • Desktop main suite (3408) and renderer suite (5071) pass; typecheck (web+node), lint (0 errors), ipc:check, i18n:check, docs-impact + docs:build all green.
  • Not run: live-Electron manual smoke (headless env) — recommend a quick real-app pass on the open-note full-mode tag case before release.

Test plan

  • Right-click an empty note → Apply Template → content appears, no dialog.
  • Right-click a note with content → Apply Template → confirm dialog; verify both replace choices.
  • Open a note in the editor, apply a tag-bearing template in full mode, edit the body → confirm merged tags survive.
  • ⋮ menu entry on the note page behaves the same.

@github-actions github-actions Bot added documentation Improvements or additions to documentation test labels Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit a7a2228.

Comment thread apps/desktop/src/renderer/src/pages/note.tsx Fixed
@h4yfans h4yfans marked this pull request as ready for review July 9, 2026 14:43
@h4yfans h4yfans merged commit 38ad035 into main Jul 9, 2026
15 of 16 checks passed
@h4yfans h4yfans deleted the note-template-apply branch July 9, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant