Skip to content

Commit

Permalink
be more conservative in removing whitespace
Browse files Browse the repository at this point in the history
closes #663
  • Loading branch information
jhchen committed May 14, 2016
1 parent 4ffd132 commit cd987c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ function matchText(node, delta) {
return match.length < 1 && collapse ? ' ' : match;
}
text = text.replace(/\s\s+/g, replacer.bind(replacer, true));
if (node.previousSibling == null || isLine(node.previousSibling)) {
if ((node.previousSibling == null && isLine(node.parentNode)) ||
(node.previousSibling != null && isLine(node.previousSibling))) {
text = text.replace(/^\s+/, replacer.bind(replacer, false));
}
if (node.nextSibling == null || isLine(node.nextSibling)) {
if ((node.nextSibling == null && isLine(node.parentNode)) ||
(node.nextSibling != null && isLine(node.nextSibling))) {
text = text.replace(/\s+$/, replacer.bind(replacer, false));
}
}
Expand Down
6 changes: 4 additions & 2 deletions test/unit/modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ describe('Clipboard', function() {
});

it('whitespace', function() {
let html = '<div> 0 </div> <div> <div> 1 2 <span> 3 </span> 4 </div> </div>';
let html =
'<div> 0 </div> <div> <div> 1 2 <span> 3 </span> 4 </div> </div>' +
'<div><span>5 </span><span>6 </span><span> 7</span><span> 8</span></div>';
let delta = this.clipboard.convert(html);
expect(delta).toEqual(new Delta().insert('0\n1 2 3 4'));
expect(delta).toEqual(new Delta().insert('0\n1 2 3 4\n5 6 7 8'));
});

it('inline whitespace', function() {
Expand Down

0 comments on commit cd987c0

Please sign in to comment.