selecting text, then changing applications, then regaining focus replaces selected text by a single "-"
See original GitHub issueThis bug is similar to #1730 and #2481, and is serious because it can lead to data loss.
Highlight everything in a sufficiently large codemirror editor instance (e.g., http://codemirror.net/demo/complete.html), focus on another application, then come back, and sometimes the contents of the editor is replaced by a -.
I was able to sometimes see this same problem several times with http://codemirror.net/demo/complete.html, though rarely. I will keep trying to make this more clearly reproducible. I’m reporting this mainly in the hopes that it’ll be useful to somebody, and perhaps you could better explain the mysterious code in codemirror.js around
minimal = hasCopyEvent &&
More details and a workaround…
Sometimes users of SageMathCloud (using Codemirror 4.x) have complained that their entire file was replaced by a dash. I’ve never seen this myself, so I didn’t understand how it could happen. It turns out, they copied the contents of a file from Codemirror (via select all) to an external editor, then come back to SageMathCloud, changed tabs in SageMathCloud (which causes a focus event in CodeMirror), and find that their file is replaced by a -. I never saw this because I do all my editing in CodeMirror. With SMC, this happens every single time, and is pretty disturbing. It only happens on Chrome and Safari (at least it doesn’t happen on Firefox).
Since this is a pretty significant problem (the whole file is deleted), as a workaround, I replaced the line in codemirror.js
minimal = hasCopyEvent &&
by
minimal = false && hasCopyEvent &&
Doing this completely stops the problem from happening (not surprisingly, looking at the source code). Of course this causes another problem, where the sometimes selection vanishes when returning to the browser – however, that is a much less serious bug.
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (4 by maintainers)
I’ve also found why this bug triggered. It seems to be due to a Chrome plugin https://github.com/jswanner/DontFuckWithPaste
Adding the site to the ‘exclude URL pattern’ list, will not trigger the bug. It is probably due to assumptions on your part about an expected series of events, which that plugin changes.
Exactly. DFWP disable clipboard events, in order to block sites from nefarious or annoying behaviors – e.g., forms not allowing you to paste in password confirmation field.
In this case, even with DFWP enabled, the copy & paste still worked with <1000 characters. It was only over this limit that the JS injected by DFWP triggered the hidden textarea hack in CM, resulting in the
"-"
.Anyway, I agree with the sentiment; you’re certainly asking for trouble when you install a Chrome extension that modifies your clipboard behavior – even if the intent is to restore its original functionality 😃
Thanks for the quick patch! Much appreciated.