fix: handle local mindmap trash and block insertion
This commit is contained in:
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user