New lines are removed on copy
See original GitHub issueDo 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
What’s the expected behavior?
The new lines must be copied over
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is fixed in the latest version of
slate-react
, thanks @Slapbox!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:But unfortunately,
innerText
have the same problem astextContent
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.