Skip to content

Commit

Permalink
Fix block embed attributor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jul 6, 2023
1 parent b65abc1 commit dc49c1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blots/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ class Scroll extends ScrollBlot {
renderBlock.key,
renderBlock.value,
) as EmbedBlot;
this.insertBefore(blockEmbed, refBlot || undefined);
Object.keys(renderBlock.attributes).forEach(name => {
blockEmbed.format(name, renderBlock.attributes[name]);
});
this.insertBefore(blockEmbed, refBlot || undefined);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions test/fuzz/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const attributeDefs: {
{ name: 'height', values: ['100', '200', '300'] },
],
blockEmbed: [
{ name: 'align', values: ['center', 'right'] },
{ name: 'width', values: ['100', '200', '300'] },
{ name: 'height', values: ['100', '200', '300'] },
],
Expand Down
20 changes: 19 additions & 1 deletion test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ describe('Editor', function () {
});
});

it('inserts formatted block embeds', function () {
it('inserts formatted block embeds (styles)', function () {
const editor = this.initialize(Editor, `<p></p>`);
editor.insertContents(
0,
Expand All @@ -944,6 +944,24 @@ describe('Editor', function () {
]);
});

it('inserts formatted block embeds (attributor)', function () {
const editor = this.initialize(Editor, `<p></p>`);
editor.insertContents(
0,
new Delta()
.insert('a\n')
.insert({ video: '#' }, { align: 'center' })
.insert({ video: '#' }, { align: 'center' })
.insert('\nd'),
);
expect(editor.getDelta().ops).toEqual([
{ insert: 'a\n' },
{ insert: { video: '#' }, attributes: { align: 'center' } },
{ insert: { video: '#' }, attributes: { align: 'center' } },
{ insert: '\nd\n' },
]);
});

it('inserts inline embeds to bold text', function () {
const editor = this.initialize(Editor, `<p><strong>ab</strong></p>`);
editor.insertContents(1, new Delta().insert({ image: '#' }));
Expand Down

0 comments on commit dc49c1b

Please sign in to comment.