Skip to content

Commit

Permalink
fix copy/convert block embed within block
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed May 3, 2019
1 parent 63f1c66 commit bb7ad87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
19 changes: 13 additions & 6 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
StyleAttributor,
BlockBlot,
} from 'parchment';
import { BlockEmbed } from '../blots/block';
import Quill from '../core/quill';
import logger from '../core/logger';
import Module from '../core/module';
Expand Down Expand Up @@ -427,13 +428,19 @@ function matchList(node, delta) {
return applyFormat(delta, 'list', list);
}

function matchNewline(node, delta) {
function matchNewline(node, delta, scroll) {
if (!deltaEndsWith(delta, '\n')) {
if (
isLine(node) ||
(delta.length() > 0 && node.nextSibling && isLine(node.nextSibling))
) {
delta.insert('\n');
if (isLine(node)) {
return delta.insert('\n');
}
if (delta.length() > 0 && node.nextSibling) {
if (isLine(node.nextSibling)) {
return delta.insert('\n');
}
const match = scroll.query(node.nextSibling);
if (match && match.prototype instanceof BlockEmbed) {
return delta.insert('\n');
}
}
}
return delta;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ describe('Clipboard', function() {
);
});

it('block embeds within blocks', function() {
const delta = this.clipboard.convert({
html: '<h1>01<iframe src="#"></iframe>34</h1><p>67</p>',
});
expect(delta).toEqual(
new Delta()
.insert('01\n', { header: 1 })
.insert({ video: '#' }, { header: 1 })
.insert('34\n', { header: 1 })
.insert('67'),
);
});

it('attributor and style match', function() {
const delta = this.clipboard.convert({
html: '<p style="direction:rtl;">Test</p>',
Expand Down

0 comments on commit bb7ad87

Please sign in to comment.