From 6203a0e9fa298fd69b256f4d762b4ba6933042b6 Mon Sep 17 00:00:00 2001 From: Mike Harris Date: Wed, 11 Jun 2025 20:08:40 -0400 Subject: [PATCH] make CollabLineBreakNode respect type --- packages/lexical-yjs/src/CollabLineBreakNode.ts | 11 ++++++----- packages/lexical-yjs/src/Utils.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/lexical-yjs/src/CollabLineBreakNode.ts b/packages/lexical-yjs/src/CollabLineBreakNode.ts index 976465495c6..6f04a4b7777 100644 --- a/packages/lexical-yjs/src/CollabLineBreakNode.ts +++ b/packages/lexical-yjs/src/CollabLineBreakNode.ts @@ -17,13 +17,13 @@ export class CollabLineBreakNode { _map: YMap; _key: NodeKey; _parent: CollabElementNode; - _type: 'linebreak'; + _type: string; - constructor(map: YMap, parent: CollabElementNode) { + constructor(map: YMap, parent: CollabElementNode, type?: string) { this._key = ''; this._map = map; this._parent = parent; - this._type = 'linebreak'; + this._type = type || 'linebreak'; } getNode(): null | LineBreakNode { @@ -40,7 +40,7 @@ export class CollabLineBreakNode { } getType(): string { - return this._type; + return this._type || 'linebreak'; } getSize(): number { @@ -63,8 +63,9 @@ export class CollabLineBreakNode { export function $createCollabLineBreakNode( map: YMap, parent: CollabElementNode, + type?: string, ): CollabLineBreakNode { - const collabNode = new CollabLineBreakNode(map, parent); + const collabNode = new CollabLineBreakNode(map, parent, type); map._collabNode = collabNode; return collabNode; } diff --git a/packages/lexical-yjs/src/Utils.ts b/packages/lexical-yjs/src/Utils.ts index 87a35d5f2fd..d27c383f28f 100644 --- a/packages/lexical-yjs/src/Utils.ts +++ b/packages/lexical-yjs/src/Utils.ts @@ -145,7 +145,7 @@ export function $createCollabNodeFromLexicalNode( } else if ($isLineBreakNode(lexicalNode)) { const map = new YMap(); map.set('__type', 'linebreak'); - collabNode = $createCollabLineBreakNode(map, parent); + collabNode = $createCollabLineBreakNode(map, parent, nodeType); } else if ($isDecoratorNode(lexicalNode)) { const xmlElem = new XmlElement(); collabNode = $createCollabDecoratorNode(xmlElem, parent, nodeType); @@ -208,7 +208,7 @@ export function $getOrInitCollabNodeFromSharedType( return $createCollabElementNode(sharedType, targetParent, type); } else if (sharedType instanceof YMap) { if (type === 'linebreak') { - return $createCollabLineBreakNode(sharedType, targetParent); + return $createCollabLineBreakNode(sharedType, targetParent, type); } return $createCollabTextNode(sharedType, '', targetParent, type); } else if (sharedType instanceof XmlElement) {