Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Copy/paste between editors strips soft returns #1154

Open
DawnWright opened this issue Apr 20, 2017 · 3 comments
Open

Copy/paste between editors strips soft returns #1154

DawnWright opened this issue Apr 20, 2017 · 3 comments

Comments

@DawnWright
Copy link
Contributor

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

@pascalopitz
Copy link

Same issue as the one I filed just now? #1780

@thibaudcolas
Copy link
Contributor

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.

@hama0511
Copy link

same here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants