From 7370a556ff77b1761184823d21971d6f5e025c72 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Thu, 6 Jul 2023 17:16:46 +0800 Subject: [PATCH] Make sure blot is attached before calling formatAt --- blots/scroll.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/blots/scroll.ts b/blots/scroll.ts index 89efb3a783..1c1120d402 100644 --- a/blots/scroll.ts +++ b/blots/scroll.ts @@ -192,8 +192,10 @@ class Scroll extends ScrollBlot { renderBlocks.forEach(renderBlock => { if (renderBlock.type === 'block') { - const block = this.createBlock(renderBlock.attributes); - this.insertBefore(block, refBlot || undefined); + const block = this.createBlock( + renderBlock.attributes, + refBlot || undefined, + ); insertInlineContents(block, 0, renderBlock.delta); } else { const blockEmbed = this.create( @@ -382,7 +384,7 @@ class Scroll extends ScrollBlot { return renderBlocks; } - private createBlock(attributes: AttributeMap) { + private createBlock(attributes: AttributeMap, refBlot?: Blot) { let blotName: string | undefined; const formats: AttributeMap = {}; @@ -400,6 +402,8 @@ class Scroll extends ScrollBlot { blotName ? attributes[blotName] : undefined, ) as ParentBlot; + this.insertBefore(block, refBlot || undefined); + const length = block.length(); Object.entries(formats).forEach(([key, value]) => { block.formatAt(0, length, key, value);