Skip to content

Commit

Permalink
fix #735 and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Jun 8, 2016
1 parent 5a8f3c0 commit 8e1ad43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Clipboard extends Module {
Clipboard.DEFAULTS = {
matchers: [
[Node.TEXT_NODE, matchText],
['br', matchBreak],
[Node.ELEMENT_NODE, matchNewline],
[Node.ELEMENT_NODE, matchBlot],
[Node.ELEMENT_NODE, matchSpacing],
Expand Down Expand Up @@ -242,6 +243,13 @@ function matchBlot(node, delta) {
return delta;
}

function matchBreak(node, delta) {
if (!deltaEndsWith(delta, '\n')) {
delta.insert('\n');
}
return delta;
}

function matchNewline(node, delta) {
if (!isLine(node)) return delta;
if (computeStyle(node).whiteSpace.startsWith('pre') || !deltaEndsWith(delta, '\n')) {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ describe('Clipboard', function() {
expect(delta).toEqual(new Delta().insert('\u00a0\u00a01\u00a0\u00a0', { bold: true }));
});

it('break', function() {
let html = '<div>0<br>1</div><div>2<br></div><div>3</div><div><br>4</div><div><br></div><div>5</div>';
let delta = this.clipboard.convert(html);
expect(delta).toEqual(new Delta().insert('0\n1\n2\n3\n\n4\n\n5'));
});

it('alias', function() {
let delta = this.clipboard.convert('<b>Bold</b><i>Italic</i>');
expect(delta).toEqual(new Delta().insert('Bold', { bold: true }).insert('Italic', { italic: true }));
Expand Down

0 comments on commit 8e1ad43

Please sign in to comment.