From 2c7a91e1fb07f51ac2945f5a38782f4e8871cfc6 Mon Sep 17 00:00:00 2001 From: lix-2026 Date: Tue, 26 May 2026 16:47:03 +0800 Subject: [PATCH] Fix local markdown title option persistence --- .../browser/document-editor-adapter-runtime.js | 10 ++++++++-- .../browser/sidebar-page-settings-runtime.js | 13 +++++++++++++ .../mnote-web/browser/sidebar-tree-runtime.js | 3 +++ rust/crates/mnote-web/src/routes/web_shell.rs | 3 +++ rust/crates/mnote-web/src/ssr/pages/layout.rs | 2 ++ scripts/dev-hot.js | 1 + scripts/task-dev-hot-plan-test.js | 1 + 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/rust/crates/mnote-web/browser/document-editor-adapter-runtime.js b/rust/crates/mnote-web/browser/document-editor-adapter-runtime.js index 822aa9ee..16ea7395 100644 --- a/rust/crates/mnote-web/browser/document-editor-adapter-runtime.js +++ b/rust/crates/mnote-web/browser/document-editor-adapter-runtime.js @@ -163,8 +163,13 @@ import { const syncPageAggregateScript = (session, aggregate) => { if (!session || !aggregate) return; const scriptId = session.pageAggregateScriptId || '__MNOTE_PAGE_AGGREGATE__'; - const node = document.getElementById(scriptId); - if (!node) return; + let node = document.getElementById(scriptId); + if (!node) { + node = document.createElement('script'); + node.id = scriptId; + node.type = 'application/json'; + document.body.appendChild(node); + } try { node.textContent = JSON.stringify(aggregate); node.setAttribute('data-mnote-page-aggregate-synced-at', String(Date.now())); @@ -343,6 +348,7 @@ import { } const aggregate = options.aggregate || await fetchPageAggregateForPane(descriptor); const bootstrap = buildBootstrapFromAggregate(aggregate, descriptor, paneRole); + syncPageAggregateScript({ pageAggregateScriptId: bootstrap.pageAggregateScriptId }, aggregate); const runtimeDescriptor = { paneRole, root, observability, aggregate, bootstrap }; updatePaneChrome(runtimeDescriptor); if (paneRole === 'secondary' && workspace instanceof HTMLElement) { diff --git a/rust/crates/mnote-web/browser/sidebar-page-settings-runtime.js b/rust/crates/mnote-web/browser/sidebar-page-settings-runtime.js index dc15b1de..8a2edf3f 100644 --- a/rust/crates/mnote-web/browser/sidebar-page-settings-runtime.js +++ b/rust/crates/mnote-web/browser/sidebar-page-settings-runtime.js @@ -638,6 +638,19 @@ export function createSidebarPageSettingsRuntime(context) { if (!response.ok || !payload || payload.ok !== true) { throw new Error(payload && payload.error && payload.error.message ? payload.error.message : 'page_settings_save_failed_' + response.status); } + var script = document.getElementById('__MNOTE_PAGE_AGGREGATE__'); + if (script) { + try { + var aggregate = JSON.parse(script.textContent || 'null'); + if (aggregate && typeof aggregate === 'object') { + aggregate.layout = aggregate.layout && typeof aggregate.layout === 'object' ? aggregate.layout : {}; + aggregate.layout.pageOptions = Object.assign({}, nextOptions); + aggregate.layout_options = Object.assign({}, nextOptions); + script.textContent = JSON.stringify(aggregate); + script.setAttribute('data-mnote-page-options-synced-at', String(Date.now())); + } + } catch (_) {} + } document.documentElement.setAttribute('data-mnote-page-options-saved', 'true'); } catch (error) { pageUiState.pageOptions = previous; diff --git a/rust/crates/mnote-web/browser/sidebar-tree-runtime.js b/rust/crates/mnote-web/browser/sidebar-tree-runtime.js index 16be0a6e..6b65974c 100644 --- a/rust/crates/mnote-web/browser/sidebar-tree-runtime.js +++ b/rust/crates/mnote-web/browser/sidebar-tree-runtime.js @@ -2764,6 +2764,9 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim schedulePendingLocalFolderRestoreFocus(); window.addEventListener('mnote:primary-document-activated', function(event) { var detail = event && event.detail ? event.detail : {}; + pageUiState.pageOptions = null; + applyPageOptionsToShell(); + if (isPageSettingsOpen()) renderPageSettingsPopover(); selectSidebarFileTreeDocument(detail.documentId, { scrollIntoView: false }); }); restoreSidebarTreeTab(); diff --git a/rust/crates/mnote-web/src/routes/web_shell.rs b/rust/crates/mnote-web/src/routes/web_shell.rs index 209d2051..ba50b150 100644 --- a/rust/crates/mnote-web/src/routes/web_shell.rs +++ b/rust/crates/mnote-web/src/routes/web_shell.rs @@ -2409,6 +2409,9 @@ mod tests { assert!(DOCUMENT_SESSION_RUNTIME_JS.contains("createDocumentSessionRuntime")); assert!(DOCUMENT_SESSION_RUNTIME_JS.contains("getOrCreateDocumentSession")); assert!(DOCUMENT_SESSION_RUNTIME_JS.contains("persistSession")); + assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("document.createElement('script')")); + assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS + .contains("syncPageAggregateScript({ pageAggregateScriptId")); assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("document-slash-position-runtime.js")); assert!(DOCUMENT_SLASH_POSITION_RUNTIME_JS.contains("observeSlashMenuPosition")); assert!(DOCUMENT_SLASH_POSITION_RUNTIME_JS.contains("scheduleSlashMenuPosition")); diff --git a/rust/crates/mnote-web/src/ssr/pages/layout.rs b/rust/crates/mnote-web/src/ssr/pages/layout.rs index 14a717eb..9f1ea9ed 100644 --- a/rust/crates/mnote-web/src/ssr/pages/layout.rs +++ b/rust/crates/mnote-web/src/ssr/pages/layout.rs @@ -907,6 +907,8 @@ mod tests { assert!(SIDEBAR_TREE_RUNTIME_JS.contains("/api/dev/hot-reload")); assert!(SIDEBAR_TREE_RUNTIME_JS.contains("data-mnote-dev-hot-reload")); assert!(SIDEBAR_TREE_RUNTIME_JS.contains("window.clearInterval(timer)")); + assert!(SIDEBAR_TREE_RUNTIME_JS.contains("mnote:primary-document-activated")); + assert!(SIDEBAR_TREE_RUNTIME_JS.contains("pageUiState.pageOptions = null")); } #[test] diff --git a/scripts/dev-hot.js b/scripts/dev-hot.js index e49ed49f..1fc712dc 100644 --- a/scripts/dev-hot.js +++ b/scripts/dev-hot.js @@ -21,6 +21,7 @@ function cargoWatchCommand(env = process.env) { const extraArgs = String(env.MNOTE_WEB_DEV_HOT_CARGO_WATCH_ARGS || "").trim(); const watchArgs = [ "-w crates/mnote-web/src", + "-w crates/mnote-web/browser", "-w crates/mnote-web/Cargo.toml", "-w Cargo.toml", "-x \"run -p mnote-web --bin mnote-web\"", diff --git a/scripts/task-dev-hot-plan-test.js b/scripts/task-dev-hot-plan-test.js index 49c1f668..0c7f64e7 100644 --- a/scripts/task-dev-hot-plan-test.js +++ b/scripts/task-dev-hot-plan-test.js @@ -13,6 +13,7 @@ assert.equal(env.MNOTE_WEB_DEV_HOT_RELOAD, "1"); assert.match(env.MNOTE_WEB_CMD, /cargo watch/); assert.match(env.MNOTE_WEB_CMD, /run -p mnote-web --bin mnote-web/); assert.match(env.MNOTE_WEB_CMD, /crates\/mnote-web\/src/); +assert.match(env.MNOTE_WEB_CMD, /crates\/mnote-web\/browser/); assert.equal(env.FRONTEND_PORT, "3200"); console.log(JSON.stringify({ ok: true, command: env.MNOTE_WEB_CMD }, null, 2));