Fix local markdown title option persistence

This commit is contained in:
lix-2026
2026-05-26 16:47:03 +08:00
parent bb17513821
commit 2c7a91e1fb
7 changed files with 31 additions and 2 deletions
@@ -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) {
@@ -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;
@@ -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();
@@ -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"));
@@ -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]
+1
View File
@@ -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\"",
+1
View File
@@ -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));