draft-js icon indicating copy to clipboard operation
draft-js copied to clipboard

Copy/paste between editors strips soft returns

Open DawnWright opened this issue 8 years ago • 3 comments

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

DawnWright avatar Apr 20 '17 18:04 DawnWright

Same issue as the one I filed just now? https://github.com/facebook/draft-js/issues/1780

pascalopitz avatar Jun 01 '18 01:06 pascalopitz

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.

thibaudcolas avatar Jun 14 '18 22:06 thibaudcolas

same here

hama0511 avatar Oct 20 '22 06:10 hama0511