Skip to content

Commit

Permalink
Fix embed inherits formats unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 1, 2023
1 parent 663e9bd commit 665d30c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Editor {
) {
isImplicitNewlineAppended = true;
}
const [leaf] = this.scroll.leaf(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 Down
10 changes: 10 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,16 @@ describe('Editor', function () {
);
});

it('insert inline embed to the middle of formatted content', function () {
const editor = this.initialize(Editor, '<p><strong>0123</strong></p>');
editor.applyDelta(
new Delta().retain(2).insert({ image: '/assets/favicon.png' }),
);
expect(this.container).toEqualHTML(
'<p><strong>01</strong><img src="/assets/favicon.png"><strong>23</strong></p>',
);
});

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

0 comments on commit 665d30c

Please sign in to comment.