fix: handle local mindmap trash and block insertion

This commit is contained in:
lix-2026
2026-05-20 11:19:42 +08:00
parent b4c8bcb647
commit 3feeaab3cb
9 changed files with 250 additions and 87 deletions
+39 -1
View File
@@ -3349,6 +3349,38 @@ mod tests {
"mnote.leptos-tiptap-spike.document:mindmap-object:doc-a:mind-a"
);
}
#[test]
fn mindmap_empty_paragraph_has_textblock_boundary_size() {
let node = json!({
"type": "paragraph",
"attrs": {
"mnoteBlockType": "mindmap",
"mindmapId": "思维导图123456.json",
"rootNodeId": "root",
"projectionVersion": 1
}
});
assert_eq!(prosemirror_node_size(&node), Some(2));
let document = json!({
"type": "doc",
"content": [
{"type": "paragraph", "content": [{"type": "text", "text": ""}]},
node,
{"type": "paragraph", "content": [{"type": "text", "text": ""}]}
]
});
assert_eq!(
top_level_block_boundary_position(&document, 1, true),
Some(3)
);
assert_eq!(
top_level_block_boundary_position(&document, 1, false),
Some(5)
);
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -5335,7 +5367,13 @@ fn prosemirror_node_size(node: &Value) -> Option<u32> {
Some("hardBreak") | Some("horizontalRule") => Some(1),
_ => {
let Some(children) = node.get("content").and_then(Value::as_array) else {
return Some(1);
return Some(match node.get("type").and_then(Value::as_str) {
Some("paragraph") | Some("heading") | Some("blockquote")
| Some("codeBlock") | Some("bulletList") | Some("orderedList")
| Some("taskList") | Some("listItem") | Some("taskItem") | Some("table")
| Some("tableRow") | Some("tableCell") | Some("tableHeader") => 2,
_ => 1,
});
};
let content_size = children.iter().try_fold(0_u32, |acc, child| {