Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste by using middle click in firefox not working #931

Closed
alex-sl-eng opened this issue Nov 7, 2012 · 33 comments
Closed

Paste by using middle click in firefox not working #931

alex-sl-eng opened this issue Nov 7, 2012 · 33 comments

Comments

@alex-sl-eng
Copy link

Middle click to paste text in CodeMirror2 doesn't work in Firefox browser but works in Chrome.

@marijnh
Copy link
Member

marijnh commented Nov 7, 2012

This is a known issue 1. It doesn't seem to be solveable without patching Firefox.

@lilydjwg
Copy link

Instead of patching Firefox, I guess an extension may work.

@TheTechmage
Copy link

Since no one has linked to it already, here is the relevant bug within Firefox's Bugzilla. It looks like there are options that currently work in the developer edition of Firefox (I tried the first provided example, turned the <p> element into a <textarea> and the code worked). It appears that the FF team are still trying to make sure that the clipboard API standard gets nailed down first before this will get fixed in CodeMirror.

@frabjous
Copy link

The bug in Firefox's Bugzilla linked to by frostyfrog was marked as resolved about a month ago, but the problem persists for codemirror. Any progress on this?

@marijnh
Copy link
Member

marijnh commented Mar 30, 2017

Not sure what they are supposed to have fixed there, but in Firefox nightly there's still no paste event for middle-click pasting.

@frabjous
Copy link

frabjous commented May 3, 2017

The following minimal HTML will fire the onpaste event in Firefox 55 (linux) with a middle click:

<html>
<body>
<div width="100%" contenteditable onpaste="alert('you pasted');" >
  Middle click here
</div>
</body>
</html>

It also works on textareas, etc., even without the contenteditable attribute.

I can't figure out how to make that work for codeMirror, however, if it is possible.

@frabjous
Copy link

Middle click works fine to paste in Firefox with the similar EditArea javascript editor -- Example here. How did they manage it?

@lilydjwg
Copy link

lilydjwg commented Oct 26, 2017

@frabjous it's a big textarea, with all normal features like GTK editing keys available. The colorful text is laid under it.

It doesn't support multiple selections however.

@nthiery
Copy link

nthiery commented Jan 17, 2018

A fix would be most welcome, e.g. for our teaching with Jupyter under linux.

Thanks in advance!

@lilydjwg
Copy link

I'm annoyed by Jupyter not supporting middle-click paste just yesterday....There is no way to copy a value from output to the input without this feature when I've mapped Ctrl-C to interrupt the kernel instead.

@simcop2387
Copy link

Wanted to chime in that there's also a related Firefox bug ticket open about this issue too. https://bugzilla.mozilla.org/show_bug.cgi?id=953389

@suvayu
Copy link

suvayu commented May 10, 2018

The original FF issue has been resolved. Does this mean we can have this fixed? I'm using Jupyter, and middle click not working severely limits my productivity.

@marijnh
Copy link
Member

marijnh commented May 11, 2018

I'm still not seeing any paste events generated for middle clicks on uneditable elements in Firefox 59, so no, I guess the functionality we need to make this work still isn't there.

@suvayu
Copy link

suvayu commented May 11, 2018

Hi @marijnh, I can middle click paste pretty much everywhere in FF on a wide range of websites. Could you be a bit more specific (sorry, I'm not a web developer). Maybe I could help test and narrow down the exact issue?

PS: the latest release is FF 60.

@marijnh
Copy link
Member

marijnh commented May 12, 2018

The thing that looks editable in CodeMirror isn't actually editable on the HTML level (it's static content, and focus is put on a hidden textarea), so Firefox doesn't understand that it should allow paste when this element is middle-clicked and doesn't generate the events necessary to access the clipboard.

@suvayu
Copy link

suvayu commented May 13, 2018

Hi @marijnh, I had a look at the generated html. I'm not sure how to reproduce a minimal example so that I can file a bug report on the FF bugzilla. I feel waiting for the issue to be fixed without a specific bug report on the FF bugzilla isn't going to help the situation. I would be happy to file the report, and follow up, if you could help me create a minimal example.

Thanks

@marijnh
Copy link
Member

marijnh commented May 15, 2018

Minimal example: an empty document with a paste handler registered on the body. In Chrome, if you middle-click on the document the paste handler fires and can move focus to, say, a textarea to intercept the paste. In Firefox, it nothing happens.

@suvayu
Copy link

suvayu commented May 15, 2018

Hi @marijnh, sorry to repeat myself. I am not a web developer (only good with languages like Python, C++, etc), and don't know how to create an example from your description of the issue. Could you please help with a code snippet I could work with?

@lilydjwg
Copy link

Here's one:

<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<title>Test paste events</title>
<body>
</body>
<script type="text/javascript">
<!--
  document.onpaste = function(e) {
    const p = document.createElement('p')
    p.textContent = "You've pasted something of types " + e.clipboardData.types
    document.body.appendChild(p)
  }
//-->
</script>
</html>

See it live.

This page shows when something is pasted. Middle-button pastes work in Google Chrome but not Firefox.

@suvayu
Copy link

suvayu commented May 15, 2018

Okay, perfect! Now I'll follow up with the FF bugzilla.

@suvayu
Copy link

suvayu commented May 15, 2018

You can find the new bug report here.

Cheers,

@frabjous
Copy link

Incidentally, with the following small changes to the mwe, it already works in firefox:

<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<title>Test paste events</title>
<body contenteditable>
</body>
<script type="text/javascript">
<!--
  document.onpaste = function(e) {
    const p = document.createElement('p')
    p.textContent = "You've pasted something of types " + e.clipboardData.types
    document.body.appendChild(p)
    return false;
  }
//-->
</script>
</html>

That is, adding the "contenteditable" flag to the body tag makes it generate the events. The return false at the end of the function prevents it from actually pasting in the contents, as it normally would.

I have no idea if these changes are compatible with the rest of codemirror's codebase.

@marijnh
Copy link
Member

marijnh commented May 15, 2018

See the inputStyle option, but that is unfortunately not very solid yet. There are plans to rewrite the library to work with contentEditable from the base up, which would sidestep such issues, but it's not clear yet how and when that will really happen.

@adrianheine
Copy link
Contributor

This is a issue that's difficult if not impossible to solve with the fundamental approach currently taken by CodeMirror.

We are working on a rewrite (CodeMirror 6) that will address this issue, and we are currently raising money for this work: See the announcement for more information about the rewrite and a demo.

Note that CodeMirror 6 is by no means stable or usable in production, yet. It's highly unlikely that we pick up this issue for CodeMirror 5, though.

@adrianheine adrianheine added this to the Fixed in rewrite milestone Sep 6, 2018
@nchevobbe
Copy link
Contributor

Hello there, I'm currently monkey-patching the codeMirror version we use in Firefox DevTools, and everything seems to work fine (using dispatchEvent instead of focusing the input on scroller's paste).
Could someone assign me the bug? I'll open a PR shortly.

@marijnh marijnh assigned marijnh and unassigned marijnh Jan 18, 2019
@marijnh
Copy link
Member

marijnh commented Jan 18, 2019

Apparently not, github won't let me assign this to you (I guess you can only assign team members?). But don't let that stop you!

@nchevobbe
Copy link
Contributor

nchevobbe commented Jan 18, 2019 via email

@marijnh
Copy link
Member

marijnh commented Jan 22, 2019

This was finally fixed in #5751 (but see also #5754 )

@marijnh marijnh closed this as completed Jan 22, 2019
@cu
Copy link

cu commented May 14, 2020

I think this might need to be reopened; I can't middle-click to paste on any of the demos of the codemirror.net site with Firefox 76.0 on Ubuntu 19.10.

Perhaps worth noting that it does appear to work on the CM6 demo site.

@marijnh
Copy link
Member

marijnh commented May 14, 2020

It still works for me (Firefox 75 and 76 on Debian)...

@dmitry-at-publons
Copy link

dmitry-at-publons commented May 14, 2020

Trying demos on codemirror.net with Firefox 76.0.1 on Ubuntu 18.04: can paste, but can't copy by selecting or double clicking.

Same behaviour on https://codemirror.net/6/.

@lilydjwg
Copy link

lilydjwg commented May 15, 2020

And it pastes the clipboard selection, not the primary selection as native applications do.

Uh I remember wrong. It doesn't paste what I select in the CodeMirror editor; it does paste what I select outside the CodeMirror editor. (It works weird this way to me.)

@nchevobbe
Copy link
Contributor

Trying demos on codemirror.net with Firefox 76.0.1 on Ubuntu 18.04: can paste, but can't copy by selecting or double clicking.

Same behaviour on https://codemirror.net/6/.

Yes, this is a known issue on the Firefox side: https://bugzilla.mozilla.org/show_bug.cgi?id=1593761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests