From f06ab5542d7da65ca520cfc9155f785255964717 Mon Sep 17 00:00:00 2001 From: ZDDC Date: Mon, 8 Jun 2026 08:35:28 -0500 Subject: [PATCH] feat(browse): Cancel button on the identity-rename cue Adds a Cancel button alongside "Rename file & reopen" that discards the manual identity-field edits and restores the filename-derived values (leaving the rest of the front matter + body untouched), then recomputes dirty + the cue. Co-Authored-By: Claude Opus 4.8 (1M context) --- browse/js/preview-markdown.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/browse/js/preview-markdown.js b/browse/js/preview-markdown.js index bd22c82..b5999b8 100644 --- a/browse/js/preview-markdown.js +++ b/browse/js/preview-markdown.js @@ -849,9 +849,35 @@ btn.addEventListener('click', function () { renameToMatch(newName); }); fmWarn.appendChild(btn); } + // Cancel: discard the identity edits, restoring the filename values. + var cancelBtn = document.createElement('button'); + cancelBtn.type = 'button'; + cancelBtn.className = 'btn btn-sm md-fm__revert'; + cancelBtn.textContent = 'Cancel'; + cancelBtn.title = 'Discard these identity edits and restore the filename values.'; + cancelBtn.addEventListener('click', function () { revertIdentityEdits(); }); + fmWarn.appendChild(cancelBtn); fmWarn.style.display = 'flex'; } + // Revert the identity fields in the front matter to the filename- + // derived values (undo a manual identity edit), leaving the rest of the + // front matter + body untouched. Recomputes dirty + the cue after. + async function revertIdentityEdits() { + var fid = filenameIdentity(node.name); + if (!fid) return; + var data = parseFrontMatter('---\n' + fmTextarea.value + '\n---\n').data || {}; + for (var k in fid) { + if (Object.prototype.hasOwnProperty.call(fid, k)) data[k] = fid[k]; + } + fmTextarea.value = stringifyFrontMatter(data); + var body = editor.getMarkdown(); + var h = await hashContent(assembleContent(fmTextarea.value, body)); + if (currentInstance !== instance) return; + markDirty(h !== instance.hash); + renderIdentityCue(); + } + // Rename action: persist the current buffer (so body edits aren't // lost), rename the file to match the edited identity, then reopen the // new name fresh. Server mode reopens via the ?file deep-link (reuses