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 15, 2023
1 parent 71443da commit c8dec17
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 @@ -67,10 +67,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 @@ -87,6 +83,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 c8dec17

Please sign in to comment.