You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
CodeMirror sends wrong "paste" origin with changeObj after trying to paste an image #5764
first of all, as this is my first issue here: Thank you so much for your hard work with CodeMirror!
I think I found some weird behaviour in relation with pasting events and CodeMirror. I wanted to enable a "paste image from clipboard"-functionality in my app, Zettlr, and it works extremely well except one strange issue:
If you copy an image to clipboard but provide no fallback text (for pure textareas or apps that don't support pasting clipboard images) — e.g. making a screenshot — CodeMirror acts weirdly. If you paste such an image, CodeMirror won't fire, obviously, because there's no text to paste. But after I've manually saved the image and inserted a link to the image by calling cm.replaceSelection(), the next time I type anything, CodeMirror suddenly throws out a changeObj on its beforeChange event that has its origin set to "paste", and not to "insert", as it should be.
What I think is happening is when the textarea receives the paste-event, CodeMirror sets an internal origin-flag to "paste", afterwards detects that there is no text in the past event, aborts the paste operation but leaves the flag to "paste" and as soon as the next input happens, it uses the "paste" flag and does not reset it to whatever input is happening.
Steps to Reproduce
Open any CodeMirror instance that works using a <textarea>-tag (any of the demos should do)
Attach an event listener to the beforeChange-event that simply console.logs the changeObj: editor.on('beforeChange', (cm, changeObj) => { console.log(changeObj) })
Make a screenshot or otherwise load into the clipboard an image that has no fallback text
Try to paste. Nothing should happen.
Type any character.
In the console, the changeObj should appear, featuring a "paste" origin, when it should say "input".
Affected Browsers
I've tested this with
Chrome 71
Safari 12.0.2
Firefox 64
If you need any more information, please just ask! :)
Your diagnosis was pretty accurate—attached patch switches to a timestamp, rather than a boolean flag, so that if no input is found after a paste event, the "paste" origin doesn't get attached to the next input event.
Activity
marijnh commentedon Feb 4, 2019
Your diagnosis was pretty accurate—attached patch switches to a timestamp, rather than a boolean flag, so that if no input is found after a paste event, the
"paste"origin doesn't get attached to the next input event.nathanlesage commentedon Feb 4, 2019
Thank you very much for your quick response! :)
I‘m looking forward to the release!
Prevent text-less paste from messing up the origin of the next text i…
Update from master (#1)
Prevent text-less paste from messing up the origin of the next text i…