feat: implement debounced autosave with strict LocalStorage garbage collection (Stage 2 Task B)
This commit is contained in:
@@ -92,6 +92,20 @@ export async function initEditor(elementId, dotNetHelper, initialMarkdown) {
|
||||
}
|
||||
});
|
||||
|
||||
// Hook into the Crepe content update listener system with 300ms JS debounce
|
||||
let debounceTimeout = null;
|
||||
crepe.on((listener) => {
|
||||
listener.markdownUpdated((ctx, markdown, prevMarkdown) => {
|
||||
if (debounceTimeout) {
|
||||
clearTimeout(debounceTimeout);
|
||||
}
|
||||
debounceTimeout = setTimeout(() => {
|
||||
dotNetHelper.invokeMethodAsync('OnEditorContentChanged', markdown)
|
||||
.catch(err => console.error("[Milkdown] Failed to notify editor content changed:", err));
|
||||
}, 300);
|
||||
});
|
||||
});
|
||||
|
||||
// Store the editor instance in the map
|
||||
editorCache.set(elementId, crepe);
|
||||
|
||||
@@ -131,3 +145,21 @@ export async function destroyEditor(elementId) {
|
||||
editorCache.delete(elementId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely retrieves all localStorage keys starting with the "nexus-bkp-" prefix.
|
||||
*/
|
||||
export function getBackupKeys() {
|
||||
const keys = [];
|
||||
try {
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.startsWith('nexus-bkp-')) {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[Milkdown] Error listing localStorage keys:", err);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user