Skip to content

Commit

Permalink
Fix inserting inline embed not working when attributes are same
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 7, 2023
1 parent b2a9da9 commit ded4666
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class Editor {
) {
isImplicitNewlineAppended = true;
}
// @ts-expect-error
const [leaf] = this.scroll.descendant(LeafBlot, index);
const formats = merge({}, bubbleFormats(leaf));
attributes = AttributeMap.diff(formats, attributes) || {};
} else if (index > 0) {
// @ts-expect-error
const [leaf, offset] = this.scroll.descendant(LeafBlot, index - 1);
Expand All @@ -82,6 +78,13 @@ class Editor {
}
}
this.scroll.insertAt(index, key, op.insert[key]);

if (isInlineEmbed) {
// @ts-expect-error
const [leaf] = this.scroll.descendant(LeafBlot, index);
const formats = merge({}, bubbleFormats(leaf));
attributes = AttributeMap.diff(formats, attributes) || {};
}
}
scrollLength += length;
} else {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,14 @@ describe('Editor', function () {
);
});

it('prepend inline embed to another inline embed with same attributes', function () {
const editor = this.initialize(Editor, '<p><img src="#" alt="hi"/></p>');
editor.applyDelta(new Delta().insert({ image: '#' }, { alt: 'hi' }));
expect(this.container).toEqualHTML(
'<p><img src="#" alt="hi"><img src="#" alt="hi"></p>',
);
});

it('insert block embed with delete before block embed', function () {
const editor = this.initialize(
Editor,
Expand Down

0 comments on commit ded4666

Please sign in to comment.