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.

Internal copy paste is broken

See original GitHub issue

Version 0.19.16 was the last version where copy and pasting internally in the document worked as expected (keeping the formatting intact). The .fragment document is now null, and there is only a .html part, thus it falls back to onPasteText by the default core plugin. I suspect it has something to do with #716.

If you try copying and pasting the contents of http://slatejs.org/#/rich-text?_k=952y37, you see what I mean.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
danburzocommented, Aug 23, 2017

There are a hosts of problems relating to copy/paste in Chrome and Safari and they stem from a single problem:

Doing

    const r = window.document.createRange()
    r.selectNodeContents(div)
    native.removeAllRanges()
    native.addRange(r)

when the div has a single child node, on copy the content of the child node is copied instead of the entire child node (as it happens in Firefox), i.e. Webkit will copy the “inner HTML” while Firefox will copy the “outer HTML”. What this means in practice is that the fragment data, which resides on the outer HTML, will be lost to Webkit in a host of situations, and it has to fall back to the HTML content, which is a single, unstyled span.

A secondary problem is that any trailing whitespace is also lost in the process, but this can be fixed with a white-space: pre-wrap on the temporary div that gets created to hold the copy data.

I’m not sure if this behavior is intended (or what spec governs it), but I have not found a way yet to make the selection take the “outer html” in this situation. Selection.selectAllChildren() is different from Range.selectNodeContents in subtle ways but exhibits the same essential problems.

There is of course the possibility of always ensuring we have at least two child nodes by inserting a dummy node, but it needs to have non-empty content (a zero width space perhaps), and pasting into external apps will introduce these unwelcome artifacts.

Alternatively, we can theoretically use clipboardData.setData('text/plain') and clipboardData.setData('text/html') on the copy event and eschew the div thing entirely.

1reaction
czechdavecommented, Dec 15, 2017

I’m not sure if this is a separate issue or not but when copy/pasting paragraph with inlines from a “hanging selection”, the inlines don’t make it through: inline bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Copy and Paste Not Working in Windows
A chkdsk scan can help resolve copy and paste issues. To do this: Open File Explorer and select “This PC.”
Read more >
How to Fix It When Copy and Paste Isn't Working in Windows ...
Run the latest Windows Updates. An out-of-date Windows system can lead to unexpected problems like copy and paste not working. Installing the ...
Read more >
Copy + Paste (Clipboard) Issues / Not Working? - TechNet
Open an elevated command prompt. To do this, click Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run ...
Read more >
Android Studio copy/paste doesn't work [37045930]
I ran into this problem today. I found a simple, yet, still annoying fix for it. Just hit ctrl+c without anything selected in...
Read more >
How to Fix When Copy-Paste Isn't Working - Alphr
Copy-Paste Not Working in Windows 10 · Check if Windows Is Updated · Keyboard Troubleshooting · Check for Viruses · Close Open Applications...
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