<%* // ───────────────────────────────────────────────────────────────────────────── // VidIn Edit Note — Inline Comment + Running Index // ───────────────────────────────────────────────────────────────────────────── // // WHAT IT DOES: // 1. Prompts you for a note about the text at your cursor // 2. Inserts invisibly at cursor position // 3. Appends - [EDIT-N] your note to the ✏️ Edit Notes index // at the bottom of the document (creates the section if it doesn’t exist) // // HOW TO SET UP A HOTKEY: // Settings → Templater → Template Hotkeys → Add hotkey → select this file // Suggested: Cmd+Shift+E (E for Edit note) // // HOW TO USE: // 1. Place cursor in the text next to what needs attention // 2. Hit your hotkey // 3. Type your note in the prompt and press Enter // 4. The inline marker appears at cursor; the index at the bottom updates // // HOW TO RESOLVE: // Delete the marker from the text AND // delete the matching line from the ✏️ Edit Notes section // ─────────────────────────────────────────────────────────────────────────────
const file = app.workspace.getActiveFile(); if (!file) { new Notice(“No active file.”); tR += ""; return; }
const content = await app.vault.read(file);
// Auto-number: count existing markers to get the next number
const existing = content.match(/[EDIT-{noteText}%%; const entry = - **[EDIT-{noteText}`;
const sectionHeader = ”## ✏️ Edit Notes edit”;
// ── Append the index entry after Templater finishes its cursor insertion ── // setTimeout ensures Templater has completed writing the inline marker // before we read and modify the file for the index section. setTimeout(async () ⇒ { const fresh = await app.vault.read(file); let updated;
if (fresh.includes(sectionHeader)) {
// ── Section exists: insert after the last [EDIT-N] entry ──
const lines = fresh.split('\n');
let insertAfter = -1;
let headerAt = -1;
for (let i = 0; i < lines.length; i++) {
if (lines[i].includes(sectionHeader)) headerAt = i;
if (/^- \*\*\[EDIT-\d+\]\*\*/.test(lines[i])) insertAfter = i;
}
// If no entries yet, insert right after the header line
const after = insertAfter >= 0 ? insertAfter : headerAt;
lines.splice(after + 1, 0, entry);
updated = lines.join('\n');
} else {
// ── Section doesn't exist: create it before the standard footer ──
// Targets the ---\n\n*Last updated: pattern used in VidIn docs.
const footerIdx = fresh.lastIndexOf('\n---\n\n*Last updated:');
if (footerIdx >= 0) {
updated = fresh.slice(0, footerIdx)
+ '\n\n---\n\n' + sectionHeader + '\n\n' + entry
+ fresh.slice(footerIdx);
} else {
// No standard footer found — append to end of file
updated = fresh.trimEnd() + '\n\n---\n\n' + sectionHeader + '\n\n' + entry + '\n';
}
}
await app.vault.modify(file, updated);
new Notice(`Edit note #${nextNum} added.`);
}, 400);
// Insert the invisible inline marker at the cursor position tR += marker; %>