fix(editor): track dirty changes after the first autosave

CodeMirror 5 change handlers receive (instance, changeObj). The handler named the first argument change, so once the fold gutter populated __mdpFenceCache it threw on change.from.line before setDirty(true). Edits after the first autosave stayed clean: Ctrl+S and Ctrl+E skipped saving and the preview stayed stale. Use the correct signature, return early for remote setValue, and guard the cache update. Add a page regression test.
This commit is contained in:
2026-11-11 14:19:16 +08:00
parent f1bda62d84
commit 6565352ab5
2 changed files with 33 additions and 3 deletions

View File

@@ -746,11 +746,15 @@
return;
}
ed = createCodeMirrorEditor(cm);
cm.on('change', function(change) {
if (cm.__mdpFenceCache) {
// CodeMirror 5 calls change handlers as (instance, changeObj). Naming the
// first argument `change` made `change.from` undefined; once the fold
// gutter had populated __mdpFenceCache this threw before setDirty(true),
// so edits after the first autosave never saved. Keep the object second.
cm.on('change', function(instance, change) {
if (applyingRemote) return;
if (cm.__mdpFenceCache && change && change.from) {
cm.__mdpFenceCache.validTo = Math.min(cm.__mdpFenceCache.validTo, change.from.line);
}
if (applyingRemote) return;
setDirty(true);
scheduleAutosave();
updateDocumentStats(ed.value());