question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New lines are removed on copy

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What’s the current behavior?

This has been reported earlier https://github.com/ianstormtaylor/slate/issues/1635 and then a related PR was created https://github.com/ianstormtaylor/slate/pull/1644.

Somehow it doesn’t work as expected with slate@0.34.2.

In Action

new-lines-skipped

What’s the expected behavior?

The new lines must be copied over

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ianstormtaylorcommented, Aug 8, 2018

This is fixed in the latest version of slate-react, thanks @Slapbox!

2reactions
tobiasandersencommented, Jun 25, 2018

Hm, what’s weird is that it works fine in our editor — but not in the examples. I haven’t investigated what differs though. Anyway, sorry for breaking stuff. Reading on mdn, it sounds like innerText should do the trick:

As a getter, it approximates the text the user would get if they highlighted the contents of the element with the cursor and then copied to the clipboard.

But unfortunately, innerText have the same problem as textContent in that it doesn’t break child nodes.

I’m not sure about the solution proposed above though, since I believe there’re important distinctions between the different zero width space attributes (for IMEs I think?), and that it would probably also add extra line breaks for legacy browsers that don’t support the clipboard api. Maybe it could be altered to solve those cases as well though?

Another solution would be to add back some old logic, where we actually add the dummy div to the DOM, select it, and then use the selection to retrieve the text. I don’t know why, but doing it this way seems to preserve line breaks. Sadly we’d have to add back some COMPAT stuff for Firefox for this to work properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Paste as plain text, but also remove any new-line and carriage ...
Paste as plain text, but also remove any new-line and carriage return characters · Copy the required text · Paste the text in...
Read more >
Remove new lines while copy paste in JS/Angular
This happens mostly when a user copies a string with new line and paste it in an input box. In case you have...
Read more >
Removing line breaks in text copied from a flex container
I have set up a codepen here as an example. Copy the 2 lines and paste them into a text editor (or a...
Read more >
New lines change when pasting and copying - Discuss
If I copy the text from a rich text editor, then it will add a new line to the double new line (i.e.,...
Read more >
SetText replacing newline with spaces - Studio - UiPath Forum
... “Set Text” to paste this data copied from clipboard in a Text Area. However, the issue is that newline in the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found