Fixing Copy-Paste issues on Eclipse and KDE
August 10, 2008
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?
26 Comments Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed
1. bauermann | August 11, 2008 at 7:34 pm
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] | September 5, 2008 at 5:46 am
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 | October 14, 2008 at 1:39 pm
Same thing happens on Ganymede on Windows XP…
4. Marcel Heijmans | October 21, 2008 at 12:22 pm
On Kubuntu 8.04 with Ganymede same problem.
5. Carlos Rafael | November 5, 2008 at 6:29 pm
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 | November 14, 2008 at 9:36 am
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 | November 15, 2008 at 1:04 am
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 | November 16, 2008 at 6:47 pm
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 | January 12, 2009 at 11:22 am
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 | February 5, 2009 at 11:07 am
Unchecking “prevent empty clipboard” works perfectly with (almost) no loss in usability. Thanks!
11. freexe | February 23, 2009 at 2:20 pm
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. Fixing Copy-Paste issues on Eclipse and KDE « Democratic ambitions… and software dev juices | February 24, 2009 at 10:08 am
[...] post to fix this KDE/Eclipse issue. Personally I unchecked ‘Prevent empty clipboard‘ in Klipper’s [...]
13. Greg Barton | June 5, 2009 at 4:35 am
Thank you, thank you, thank you! This was driving me batshit crazy.
14. Paul Flanders | June 22, 2009 at 8:45 pm
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 | July 6, 2009 at 12:03 pm
Disable klipper worked for me.
16. Coral's Blog | July 24, 2009 at 2:15 pm
[...] } Wow, couldn’t figure out why eclipse was ignoring the clipboard. Appears to be a Klipper issue. Must have coincided with my KDE [...]
17. Peter | July 31, 2009 at 10:01 am
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 | July 31, 2009 at 11:22 am
Thanks dude!!!! :-)
Was driving me nuts.
19. brecke | August 3, 2009 at 10:39 am
many many thanks, this bug has been driving me nuts…
*puts down the gun*
20. pgraham | August 18, 2009 at 2:31 pm
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 | September 21, 2009 at 6:37 pm
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 | September 23, 2009 at 8:08 pm
(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 | September 24, 2009 at 6:51 pm
I have turned off klipper but it still happens:(
24. Luca Provenzani | September 25, 2009 at 3:53 pm
Fantastic solution:uncheck ‘Prevent empty clipboard‘ in Klipper’s settings!!
Thank you a lot!
25. kipper | October 21, 2009 at 3:20 pm
Awesome. Thanks for investigating this. I’m happy with the workaround #2. :)
KDE4
Eclipse Galileo
26. ligi | October 24, 2009 at 2:27 pm
Thanx a lot for this investigation – the uncheck solution works very fine for me!