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) <noreply@anthropic.com>
This commit is contained in:
parent
bed6231d6b
commit
f06ab5542d
1 changed files with 26 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue