fix: align local markdown conflict and title behavior
This commit is contained in:
@@ -1578,6 +1578,8 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
|
||||
|
||||
const sessionViews = (session) => Array.from(session.views.values());
|
||||
|
||||
const localFolderEventChannelKey = (session) => `${String(session?.rootUri || '').trim()}#${String(session?.documentId || '').trim()}`;
|
||||
|
||||
const detachSessionFromLocalFolderChannel = (session) => {
|
||||
const channel = session.localFolderChannel;
|
||||
if (!channel) return;
|
||||
@@ -1588,7 +1590,7 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
|
||||
} catch (_) {
|
||||
// noop
|
||||
}
|
||||
localFolderEventRegistry.delete(channel.rootUri);
|
||||
localFolderEventRegistry.delete(channel.key);
|
||||
}
|
||||
session.localFolderChannel = null;
|
||||
};
|
||||
@@ -2394,13 +2396,17 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
|
||||
if (session.sourceKind !== 'local_folder' || !session.rootUri || typeof window.EventSource !== 'function') {
|
||||
return;
|
||||
}
|
||||
let channel = localFolderEventRegistry.get(session.rootUri);
|
||||
const channelKey = localFolderEventChannelKey(session);
|
||||
let channel = localFolderEventRegistry.get(channelKey);
|
||||
if (!channel) {
|
||||
const url = new URL('/api/local-folder/events', window.location.origin);
|
||||
url.searchParams.set('rootUri', session.rootUri);
|
||||
url.searchParams.set('documentId', session.documentId);
|
||||
const eventSource = new EventSource(url.toString());
|
||||
channel = {
|
||||
key: channelKey,
|
||||
rootUri: session.rootUri,
|
||||
documentId: session.documentId,
|
||||
eventSource,
|
||||
sessions: new Map(),
|
||||
};
|
||||
@@ -2410,6 +2416,7 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
|
||||
Array.from(channel.sessions.values()).forEach((targetSession) => {
|
||||
if (!targetSession || targetSession.views.size === 0) return;
|
||||
const documentId = typeof payload.documentId === 'string' ? payload.documentId.trim() : '';
|
||||
if (!documentId) return;
|
||||
const eventKind = String(payload.eventKind || '');
|
||||
const targetsCurrentDocument = Boolean(documentId && documentId === targetSession.documentId);
|
||||
if (documentId && !targetsCurrentDocument) return;
|
||||
@@ -2435,7 +2442,7 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
|
||||
eventSource.onerror = () => {
|
||||
console.warn('mnote local folder 外部更新事件流中断,将等待浏览器自动重连');
|
||||
};
|
||||
localFolderEventRegistry.set(session.rootUri, channel);
|
||||
localFolderEventRegistry.set(channelKey, channel);
|
||||
}
|
||||
channel.sessions.set(session.key, session);
|
||||
session.localFolderChannel = channel;
|
||||
@@ -3103,6 +3110,7 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
|
||||
view.disconnectSlashObserver();
|
||||
view.disconnectSlashObserver = null;
|
||||
}
|
||||
clearSessionConflictSurface(view.session);
|
||||
if (view.mountId != null && typeof view.runtime?.unmount === 'function') {
|
||||
try {
|
||||
view.runtime.unmount(view.mountId);
|
||||
@@ -5422,6 +5430,9 @@ mod tests {
|
||||
assert!(html.contains("refreshMindmapRuntimesFromTreePayload"));
|
||||
assert!(html.contains("__MNOTE_LEPTOS_MINDMAP_BRIDGES__"));
|
||||
assert!(html.contains("/api/local-folder/events"));
|
||||
assert!(html.contains("localFolderEventChannelKey"));
|
||||
assert!(html.contains("url.searchParams.set('documentId', session.documentId);"));
|
||||
assert!(html.contains("if (!documentId) return;"));
|
||||
assert!(html.contains("new EventSource(url.toString())"));
|
||||
assert!(html.contains("localFolderEventRegistry"));
|
||||
assert!(html
|
||||
@@ -5432,6 +5443,7 @@ mod tests {
|
||||
assert!(html.contains("session.views.size === 0"));
|
||||
assert!(html.contains("targetSession.saving"));
|
||||
assert!(html.contains("lastSelfSaveSignalAt"));
|
||||
assert!(html.contains("clearSessionConflictSurface(view.session);"));
|
||||
assert!(html.contains("command: 'replaceContent'"));
|
||||
assert!(html.contains("external-change-conflict"));
|
||||
assert!(html.contains("mnote-editor-conflict-panel"));
|
||||
|
||||
Reference in New Issue
Block a user