Fixing Copy-Paste issues on Eclipse and KDE

This article describes a solution to fix a long term issue (bug?) involving copy & paste when running Eclipse on KDE.

The problem

When launching Eclipse from KDE, one might experience several types failures with cut, copy and paste actions in Eclipse. The reported misbehavior is non-deterministic, but frequent enough to degrade user experience.

Inside the editor, specially the Java or C/C++ editor, selecting text and issuing the copy action (ctrl+c or equivalent menu entry) may not copy the select text to the clipboard (no text is copied).

The cut action (ctrl+x or equivalent menu entry) erases the selected text as expected, but may not save to clipboard (text that was cut is lost!).

Even worse, after the selected text was apparently copied (or cut) correctly, the past command (ctrl+v or equivalent menu entry) does always write correctly from clipboard. Sometimes, paste only writes part of the expected text (part of the text is lost).

Fortunately, copy & paste or cut & paste does not corrupt text, it only looses text frequently.

Copy & paste never fails on text boxes in dialogs. It might fail only on text editors.

Workarounds

At the end of this article I will explain other two workarounds. But here are the simplest ones first:

In order to copy text, one may press ctrl+c twice. The second ctrl+c always copies the selected text to clipboard.

Now, to cut text, one may press ctrl+c, then ctrl+x. It happens that pressing ctrl+c first induces ctrl+x to work correctly.

When pressing ctrl+c twice or ctrl+c followed by ctrl+x, paste always works.

Deeper investigations

On KDE, copied or cut text is intercepted by the Klipper deamon, which manages KDE global clipboard. Klipper provides copy & paste compatibility among X applications. For example, with Klipper, a generic X application can copy to/from KDE application, although they do not use the same copy & paste protocol. Klipper also overcomes some X protocol limitations related to copy & paste feature. Furthermore, Klipper offers clipboard history.

With Klipper, I was able to inspect what Eclipse did actually copy to clipboard when pressing ctrl+c. I noticed that:

  • If “copy” was successfull, then the most recent entry in Klipper history contains exactly the text that was copied.
  • Sometimes eclipse inserts an empty entry into Klippers history, instead of the expected text. An empty string will be pasted, not producing any effect.
  • Frequently, the copied text appears in Klippers history, but split into several entries. In this situation, “paste” will only write the last entry. After the split, some entries may be missing.

It is even more interesting that if text becomes split in Klipper, it is not split at random chars, but on points relevant to the semantics of the text that you are editing in Eclipse!

For example, I copied the second line of Java code:

try {
   updateLaunchConfigurationDialog();
} catch (Exception e) {
   Plugin.log(e);
}

After copying the second line, “paste” produced only “updateLaunchConfiguration”, but “Dialog();” was missing. For example, on Java, if copy happens to fail on a name of a variable or a method, it always splits on a uppercase letter that starts a word of a composed name. On expressions, it copy may split exactly on delimiters or operators.

The fix

Or maybe, we should call it: Yet another workaround.

The drastic one: Remove Klipper from your taskbar. Besides clipboard history, you will potentially loose compatibility among X applications.

Another one: Open Klipper configuration dialog and uncheck ‘Prevent empty clipboard‘ in Klipper’s settings. The advantage is that you keep benefits of Klipper and only disable the feature that is known to interfere with Eclipse. But once you close an application, content that was previously copied on this application will not be available for pasting anymore.

I think that the last workaround does not solve the problem, but it is the less intrusive workaround.

In future, I will explain in another article, who we should claim about this issue: Eclipse or Klipper?

36 Responses to Fixing Copy-Paste issues on Eclipse and KDE

  1. bauermann says:

    As far as I know, the only functionality provided by Klipper is clipboard history. It’s the only thing you’ll loose by turning it off (which I always do, when logging into a fresh KDE session).

    The X Window System has had a consistent protocol for cut & paste for a long time already, and you should not have “compatibility problems” if you use applications made in the last five years or so (being conservative here, probably even older apps than that should work).

    See this description from jwz for more details.

  2. Mr.MoOx [fr] says:

    I’ had the same problem with Eclipse 3.3.
    I use the version 3.4 (ganymede) for 3 days and I don’t see this bug…

  3. J. Kelly says:

    Same thing happens on Ganymede on Windows XP…

  4. Marcel Heijmans says:

    On Kubuntu 8.04 with Ganymede same problem.

  5. Thanks for the post, I really hate this problem in Eclipse Ganymede I use in KDE. For me the Ctrl+C twice is enough for me. Because for me klipper is a must.

    With klipper I have assigned Shorcuts to invoke the menu and i use also the search feature in History. And in despite the comment about no compatibility problems in X applications. I can say that in Linux they are two clipboards (selection and Ctrl+C) and they have different stores. Klipper allows sincronize those clipboards. For example I can copy text in terminal using “selection” clipboard, invoke clipper and paste in Outlook (Crossover) that doesn’t include the selection clipboard. And i can copy using Ctrl+C, invoke klipper and paste using middle button. For me it is a very handy tool. Also Eclipse has problems with the selection clipboard too.

    Thanks,
    Carlos

  6. Paul Hopton says:

    Hi good post.
    I have experienced the problem on Eclipose 3.3. and 3.4 on Kubuntu. The problem doesn’t ocur on my Gnome machine. Your workarounds are a good suggestion, I spend most of my time working with Eclipse and this kind of problem seriously makes me think about replacing KDE With Gnome, even though I suspect the probelm does lie with Eclipse.

    I suspect the context-sensitive keyword completeion is conflicting with klipper, or rather not succesfully delegating to it.

    I’ll give things a go without klipper.

    Thanks!

  7. Karthik says:

    I think I found a “fix” for this problem.

    I am using Kubuntu 8.10 and Eclipse 3.2..

    – Open Window->Preferences
    – Search for keys
    – Select Copy command in Edit category
    – Go to modify tab

    – For me the Scheme was already “Default” and not emacs. So I simply clicked “Apply” without making any change.

    And magically, the copy started working! I even restarted Eclipse once and tested. It still works. I will try rebooting some time later. If it all it fails, I will post back.

    PS: before doing this, I unchecked and checked back the “prevent empty.. ” klipper option. Not sure if this influenced the fix. I am just mentioning for completeness.

    Source: http://dev.eclipse.org/newslists/news.eclipse.platform/msg03746.html

  8. Karthik says:

    Okay. The “fix” in previous comment is not very consistent. It works when I start the IDE after that back to square one.

    :|

  9. G Cohen says:

    I’ve recently moved to Kubuntu from Ubuntu and this little bug made my life miserable. I’ve realised this had something to do with KDE as when I log into GNOME the problem disappeared.

    I’ve used the second fix in your post and it works. Thanks.

  10. JD says:

    Unchecking “prevent empty clipboard” works perfectly with (almost) no loss in usability. Thanks!

  11. freexe says:

    I’ve also found that copying from a virtualbox client machine (windows) wont paste into eclipse, but appears in the glipper history and pastes fine into other programs.

    For ages I thought that I was just hitting Ctrl-C incorrectly, until I noticed the virtualbox bug and did a google search to find this a common issue.

    All very strange behavior IMHO.

  12. Pingback: Fixing Copy-Paste issues on Eclipse and KDE « Democratic ambitions… and software dev juices

  13. Greg Barton says:

    Thank you, thank you, thank you! This was driving me batshit crazy.

  14. This issue was totally doing my head in ……………. Until i read your fix for klipper which worked like a charm for zend5.5 on jaunty.

    Great stuff

    ta
    Paul

  15. www.kde4.de says:

    Disable klipper worked for me.

  16. Pingback: Coral's Blog

  17. Peter says:

    Thanks for this solution. I’m sure I would have had RSI within a month from hitting Ctrl+C like a machine gun all day.

  18. Bart van Deenen says:

    Thanks dude!!!! :-)
    Was driving me nuts.

  19. brecke says:

    many many thanks, this bug has been driving me nuts…

    *puts down the gun*

  20. pgraham says:

    Hey thanks, this is great. I’m still noticing some minor issues like the last couple of characters being left off when I combine mouse selecting with -v but other than that is works great! I can now actually trust that when I copy something it will actually get copied.

  21. Josh says:

    You just saved my sanity and what little hair I have left (from me pulling it out)!

    Thank you thank you thank you!!

  22. Esben Mose Hansen says:

    (Klipper sort-of-maintainer here)

    It is most probably because Eclipse is one of the programs that empties the clipboard before claiming it. If that is case, the best solution would be for Eclipse to stop doing that… at best, it is unnecessary chatter via. the X protocol. It might also introduce a race condition, especially in these multicore days, as you probably see with Klipper here.

    The bit about Klipper enabling cross-app cut&paste functionality is completely wrong; it has nothing to do with Klipper and is a basic X feature, with some additional features in the XFixes extensions.

    Klipper does 3 things:
    1. Provide a searchable history
    2. Provide optional sync. between SELECTION and PRIMARY (that is, the mouse selection and the good old clipboard)
    3. Optionally saves clipboard data if the owning application exists (that is the prevent empty feature)
    4. Finally, klipper can perform various actions from the clipboard, e.g. start a browser if the a link is selected.

    Hope that clears up some points. Sorry about the Monty P. reference.

    Of course, it might be something completely different.

  23. freeman says:

    I have turned off klipper but it still happens:(

  24. Luca Provenzani says:

    Fantastic solution:uncheck ‘Prevent empty clipboard‘ in Klipper’s settings!!
    Thank you a lot!

  25. kipper says:

    Awesome. Thanks for investigating this. I’m happy with the workaround #2. :)

    KDE4
    Eclipse Galileo

  26. ligi says:

    Thanx a lot for this investigation – the uncheck solution works very fine for me!

  27. Alex Amiryan says:

    —–BEGIN PGP SIGNED MESSAGE—–
    Hash: SHA1

    Hello. Thanks for the post. I am using Zend Studio 7 on Fedora 11 x86_64, KDE 4.3.2. I had the same problem. Now my copy/paste works after I’ve unchecked the “Prevent empty clipboard” in Klipper.

    Thanks again!
    —–BEGIN PGP SIGNATURE—–
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAksBSYUACgkQ1KOfm1RDUTEBLgCcDYrcW0y6+QQ0aWVvP6OTShL1
    BqwAoMDOSFnAeO6iCLQG5CEYKkISbvWj
    =6ELq
    —–END PGP SIGNATURE—–

  28. panzi says:

    Did you write the follow up article already? I’d like to know who to blame.

  29. Hi Daniel,

    thanks for your great investigation – this problem really drove me crazy. I allways supposed it was eclipse’s fault since it does so much in the background.
    But well, once you got used to the comfort …

    Disabling the empty option in klipper was my choice.

    regards, Ben.

  30. Pingback: Eclipse’te (Linux, KDE) Kes, Kopyala, Yapıştır Probleminin Çözümü | FatsaLife !

  31. Marc says:

    Same bug with xfce “clipman”, solved by getting rid of clipman.

  32. If I had a nickel for every time I came to techtavern.wordpress.com… Great writing.

  33. Antonio says:

    You don’t have to think that this bug is https://bugs.launchpad.net/ubuntu/+bug/11334, which is a different one.

  34. Joel says:

    Thanks for reminding me why I left Linux for good. It’s 2010, for Christ’s sake.

  35. Pingback: Eclipse ve Kubuntu Arasında Kopyala-Yapıştır Problemi | Harezmi Bilişim Çözümleri

  36. Mccopias says:

    You have made some decent points there. I looked on the internet for more information about the issue and found most people will go along with your views on this site.

Leave a reply to Benjamin Peter Cancel reply