Skip to content

Commit 89a4c94

Browse files
committed
fix(json-crdt-extensions): 🐛 correctly insert nested nodes
1 parent f4a8742 commit 89a4c94

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/json-crdt-extensions/peritext/transfer/import-html.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ class ViewRangeBuilder {
4242
const start = this.text.length;
4343
const length = node.length;
4444
const inline = !!attr?.inline;
45-
const hasType = !!type || type === 0;
46-
if (hasType && !inline) {
45+
const hasType = type === 0 || !!type;
46+
const firstChild = node[2] as PeritextMlNode;
47+
const isFirstChildInline = firstChild && (typeof firstChild === 'string' || firstChild[1]?.inline);
48+
if (hasType && !inline && isFirstChildInline) {
4749
this.text += '\n';
4850
const header =
4951
(SliceBehavior.Marker << SliceHeaderShift.Behavior) +
@@ -54,7 +56,7 @@ class ViewRangeBuilder {
5456
if (data) slice.push(data);
5557
this.slices.push(slice);
5658
}
57-
for (let i = 2; i < length; i++) this.build0(node[i] as PeritextMlNode, [...path, type]);
59+
for (let i = 2; i < length; i++) this.build0(node[i] as PeritextMlNode, type === '' ? path : [...path, type]);
5860
if (hasType && inline) {
5961
let end: number = 0,
6062
header: number = 0;

0 commit comments

Comments
 (0)