feat(M2): FR-S1/S4/S6 保存机制完善——setBody 防抖读 settings.autoSaveInterval(S1); beforeunload 冲刷+saveNow(S4); ReadDocResult 加 mtime+reloadDoc 检测外部改动(R6); store 暴露 __STORE__; save-mechanism E2E 3 项

This commit is contained in:
hunter-dev
2026-08-26 15:05:09 +08:00
parent 01ea477d18
commit 3390e91406
5 changed files with 142 additions and 6 deletions
+6
View File
@@ -38,6 +38,12 @@ export function App() {
useEffect(() => { loadVault(); loadTree(); restore(); appearance.load(); useKeymap.getState().load(); useSettings.getState().loadGpu(); }, []);
useEffect(() => { if (activeId && tabs.length > 0) { const t = tabs.find(x => x.id === activeId); if (t) openDoc(t.path).catch(() => {}); } }, []);
// FR-S4:关窗前冲刷未保存内容
useEffect(() => {
const onBeforeUnload = () => { try { useStore.getState().saveNow(); } catch {} };
window.addEventListener('beforeunload', onBeforeUnload);
return () => window.removeEventListener('beforeunload', onBeforeUnload);
}, []);
useGlobalHotkeys({ onNewDoc: () => {}, onSave: () => useStore.getState().saveNow(), onFocusSearch: () => { const el = document.querySelector('input[placeholder*="搜索"]') as HTMLInputElement; el?.focus(); }, onToggleOutline: () => layout.toggleOutline(), onCheat: () => setShowCheat(true), onSettings: () => setShowSettings(true), onFind: () => { window.dispatchEvent(new CustomEvent('dsh-toggle-find')); } });
// 编辑器样式随设置生效(FR-编辑器设置真实生效)