refactor: extract conflict panel host mount helper

This commit is contained in:
lix-2026
2026-05-25 08:38:05 +08:00
parent f33807eacc
commit 0245b09301
3 changed files with 45 additions and 4 deletions
+12 -3
View File
@@ -2139,8 +2139,6 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
const renderSessionConflictSurface = (session, message) => {
clearSessionConflictSurface(session);
sessionViews(session).forEach((view) => {
const host = view.runtimeDescriptor.root.closest('.document-pane') || view.runtimeDescriptor.root;
if (!(host instanceof HTMLElement)) return;
const runtime = window.__mnoteDocumentConflictPanelRuntime;
const handleConflictActionError = (error) => {
setSessionStatus(session, 'external-change-conflict', error instanceof Error ? error.message : String(error));
@@ -2211,6 +2209,13 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
});
}
if (runtime && typeof runtime.mountSessionConflictPanel === 'function') {
if (runtime.mountSessionConflictPanel(view.runtimeDescriptor.root, panel)) {
return;
}
}
const host = view.runtimeDescriptor.root.closest('.document-pane') || view.runtimeDescriptor.root;
if (!(host instanceof HTMLElement)) return;
const header = host.querySelector('.document-shell-header');
if (header && header.parentNode) {
header.parentNode.insertBefore(panel, header.nextSibling);
@@ -5628,6 +5633,9 @@ mod tests {
assert!(html.contains("mnote-conflict-open-diff"));
assert!(html.contains("mnote-conflict-merge-text"));
assert!(html.contains("mnote-conflict-merge-save"));
assert!(
html.contains("runtime.mountSessionConflictPanel(view.runtimeDescriptor.root, panel)")
);
assert!(html.contains("agent run"));
assert!(!html.contains(
"setInterval(() => {\n void pollLocalMarkdownExternalChange();\n }, 1200);"
@@ -5665,9 +5673,10 @@ mod tests {
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS.contains("onUseCurrent"));
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS.contains("onUseDisk"));
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS.contains("onSaveMerge"));
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS.contains("function runSessionConflictAction"));
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS.contains("function mountSessionConflictPanel"));
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS
.contains("runSessionConflictAction: runSessionConflictAction"));
assert!(DOCUMENT_CONFLICT_PANEL_RUNTIME_JS.contains("function runSessionConflictAction"));
}
#[tokio::test]