draft-js
draft-js copied to clipboard
Copy/paste between editors strips soft returns
When copying from one draft editor and then pasting into another, I am seeing soft returns get stripped. The soft returns were '\n' characters added via RichUtils.insertSoftNewline.
https://github.com/facebook/draft-js/blob/213cd764f61cc64552bddd672ae1748529d55333/src/model/modifier/RichTextEditorUtil.js#L82
Here is a small test that can be added to convertFromHTMLToContentBlocks-test.js which demonstrates the problem:
it(`must not strip soft returns`, () => {
const contents = 'a\nb'
const html_string = `
<div>${contents}</div>
`;
const blocks = convertFromHTMLToContentBlocks(html_string);
expect(blocks.contentBlocks.length).toBe(1);
expect(blocks.contentBlocks[0].text).toBe(contents);
});
result:
Expected value to be (using ===):
"a\nb"
Received:
"a b"
This happens on account of this line of code: https://github.com/facebook/draft-js/blob/507925ad60638734872dba52efa2d0b66cd94e4b/src/model/encoding/convertFromHTMLToContentBlocks.js#L357 Is there a way we can change this behavior to handle copy paste between draft editors?
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
0.11.0-alpha Chrome, MacOS
Same issue as the one I filed just now? https://github.com/facebook/draft-js/issues/1780
New PR #1784 to fix this. If you want to use this in your project right away without forking, I added the details at the end of the PR.
same here