Skip to content

Commit

Permalink
Make sure blot is attached before calling formatAt
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jul 6, 2023
1 parent b65abc1 commit 7370a55
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions blots/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = {};

Expand All @@ -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);
Expand Down

0 comments on commit 7370a55

Please sign in to comment.