Community
Participate
Working Groups
When I copied text from the Java editor of an earlier Eclipse version (such as 2.1 or 3.0M8) into the Windows clipboard and pasted it into a suitable application (such as MS Word), font and color (from syntax-highlighting) information was present. In M9, only the plain text is placed into the clipboard.
FH has something changed in StyledText$RTFWriter?
Works on Windows XP - will try on Windows NT.
Sorry, it sometimes fails on Windows XP too. Code used to go through this path (but now does not): at org.eclipse.swt.dnd.Clipboard.setContents(Clipboard.java:260) at org.eclipse.swt.custom.StyledText.setClipboardContent (StyledText.java :6637) at org.eclipse.swt.custom.StyledText.copy(StyledText.java:2149) at org.eclipse.jface.text.TextViewer.doOperation(TextViewer.java:3383) at org.eclipse.jface.text.source.SourceViewer.doOperation (SourceViewer.j ava:744) at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation (ProjectionViewer.java:1094) at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperation (J avaSourceViewer.java:151) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedS ourceViewer.doOperation(CompilationUnitEditor.java:198) at org.eclipse.jdt.internal.ui.javaeditor.ClipboardOperationAction.inter nalDoOperation(ClipboardOperationAction.java:260) at org.eclipse.jdt.internal.ui.javaeditor.ClipboardOperationAction$1.run (ClipboardOperationAction.java:226) at org.eclipse.swt.custom.BusyIndicator.showWhile (BusyIndicator.java:69) at org.eclipse.jdt.internal.ui.javaeditor.ClipboardOperationAction.run (C lipboardOperationAction.java:224) at org.eclipse.jface.action.Action.runWithEvent(Action.java:881) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:915) at org.eclipse.jface.action.ActionContributionItem.access$2 (ActionContri butionItem.java:866) at org.eclipse.jface.action.ActionContributionItem$7.handleEvent (ActionC ontributionItem.java:785) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2716) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2382) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1363) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1334) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench (Workbench.jav a:253) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141) at org.eclipse.ui.internal.ide.IDEApplication.run (IDEApplication.java:96 ) at org.eclipse.core.internal.runtime.PlatformActivator$1.run (PlatformAct ivator.java:331) at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.ja va:273) at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.ja va:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:185) at org.eclipse.core.launcher.Main.run(Main.java:638) at org.eclipse.core.launcher.Main.main(Main.java:622)
Now it goes through this path: Thread [main] (Suspended) CompilationUnitEditor$AdaptedSourceViewer (ProjectionViewer).copyToClipboard(int, int, boolean, StyledText) line: 1208 CompilationUnitEditor$AdaptedSourceViewer(ProjectionViewer).doOperation (int) line: 1121 CompilationUnitEditor$AdaptedSourceViewer(JavaSourceViewer).doOperation (int) line: 151 CompilationUnitEditor$AdaptedSourceViewer.doOperation(int) line: 198 ClipboardOperationAction.doCutCopyWithImportsOperation() line: 305 ClipboardOperationAction.internalDoOperation() line: 257 ClipboardOperationAction$1.run() line: 226 BusyIndicator.showWhile(Display, Runnable) line: 69 ClipboardOperationAction.run() line: 224 ClipboardOperationAction(Action).runWithEvent(Event) line: 881 ActionContributionItem.handleWidgetSelection(Event, boolean) line: 915 ActionContributionItem.access$2(ActionContributionItem, Event, boolean) line: 866 ActionContributionItem$7.handleEvent(Event) line: 785 EventTable.sendEvent(Event) line: 82 MenuItem(Widget).sendEvent(Event) line: 796 Display.runDeferredEvents() line: 2716 Display.readAndDispatch() line: 2382 Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 1363 Workbench.runUI() line: 1334 Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 253 PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 141 IDEApplication.run(Object) line: 96 PlatformActivator$1.run(Object) line: 331 EclipseStarter.run(Object) line: 273 EclipseStarter.run(String[], Runnable) line: 128 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object[]) line: 324 Main.basicRun(String[]) line: 185 Main.run(String[]) line: 638 Main.main(String[]) line: 622
Sorry, ignore comment #4 - code takes a different path whether "Update imports on paste" is turned on in preferences
Code now follows this path: at org.eclipse.swt.dnd.Clipboard.setContents(Clipboard.java:260) at org.eclipse.jface.text.source.projection.ProjectionViewer.copyToClipboard (ProjectionViewer.java:1206) at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation (ProjectionViewer.java:1121) at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperation (JavaSourceViewer.java:151) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewe r.doOperation(CompilationUnitEditor.java:198) at org.eclipse.jdt.internal.ui.javaeditor.ClipboardOperationAction.internalDoOpera tion(ClipboardOperationAction.java:260) at org.eclipse.jdt.internal.ui.javaeditor.ClipboardOperationAction$1.run (ClipboardOperationAction.java:226) at org.eclipse.swt.custom.BusyIndicator.showWhile (BusyIndicator.java:69) at org.eclipse.jdt.internal.ui.javaeditor.ClipboardOperationAction.run (ClipboardOperationAction.java:224) at org.eclipse.jface.action.Action.runWithEvent(Action.java:881) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:915) at org.eclipse.jface.action.ActionContributionItem.access$2 (ActionContributionItem.java:866) at org.eclipse.jface.action.ActionContributionItem$7.handleEvent (ActionContributionItem.java:785) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2716) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2382) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1363) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1334) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench (Workbench.java:253) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141) at org.eclipse.ui.internal.ide.IDEApplication.run (IDEApplication.java:96) at org.eclipse.core.internal.runtime.PlatformActivator$1.run (PlatformActivator.java:331) at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:273) at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:185) at org.eclipse.core.launcher.Main.run(Main.java:638) at org.eclipse.core.launcher.Main.main(Main.java:622)
Reassigning to JDT UI. They used to copy the RTF format to the clipboard and now they are not. There was bug 61273 which said it fixed this problem but it appears to be broken (still? again?).
This is related to folding. In order to get syntax highlighting also for the collapsed regions we would have to create a hidden StyledText in order to get valid clipboard data for the RTF transfer.
*** Bug 65373 has been marked as a duplicate of this bug. ***
Got a user question on our internal help desk about this today. If this is hard to fix maybe folding should be turned off by default and marked as experimental in v3.
*** Bug 66818 has been marked as a duplicate of this bug. ***
*** Bug 66088 has been marked as a duplicate of this bug. ***
If folding is enabled we manually copy the folded code as text only. If folding is disabled copy works as before (verified in 3.0 RC2). We could improve this in a way that we only loose color if the copied region contains folded elements. The correct fix is to get coloring back.
*** Bug 66283 has been marked as a duplicate of this bug. ***
*** This bug has been marked as a duplicate of 59459 ***
closed wrong bug as dup
*** Bug 75009 has been marked as a duplicate of this bug. ***
*** Bug 76443 has been marked as a duplicate of this bug. ***
*** Bug 78518 has been marked as a duplicate of this bug. ***
I just added a comment to bug 65645. If you agree with the comment, please say so in that bug.
Same problem with 3.1M5a W2K, copying from Eclipse Java source to programmer documentation in Word.
Does it with .java files, but not with .txt files.
That's because code folding is ON by default in .java files. Personally, I think code folding should be OFF by default in .java files so that this problem - and others - are avoided. Please see my explanation in: https://bugs.eclipse.org/bugs/show_bug.cgi?id=65645#c4
*** Bug 108279 has been marked as a duplicate of this bug. ***
Still not fixed in 3.2M5. It seems like this problem is deadlocked by the missing access to the RTFWriter in StyledText which prevents the jface.text-team to extend the ProjectionViewer or alternatively by the missing capability of the StyledText to support hidden text (as Kai mentions). To circumvent the problem I have attached a little patch that quickfixes the problem: The StyledText is used to fill the clipboard and in case the contents of the plaintext is identical to the text selected in the ProjectionViewer the RTF-data of the styled text is used as well. This means that as long as there is not hidden text in the selection the copy operation works. In org.eclipse.jface.text.source.projection.ProjectionViewer.copyToClipboard line 1570 IDocument document = getDocument(); Clipboard clipboard = new Clipboard(textWidget.getDisplay()); try { textWidget.copy(); try { Object rtfFromWidget = clipboard.getContents(RTFTransfer .getInstance()); Object textFromWidget = clipboard.getContents(TextTransfer .getInstance()); String text = document.get(offset, length); Transfer[] dataTypes; Object[] data; if (text != null && text.equals(textFromWidget)) { dataTypes = new Transfer[] { TextTransfer.getInstance(), RTFTransfer.getInstance() }; data = new Object[] { text, rtfFromWidget }; } else { dataTypes = new Transfer[] { TextTransfer.getInstance() }; data = new Object[] { text }; } clipboard.setContents(data, dataTypes); } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) throw e; // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59459 // we should either log and/or inform the user // silently fail for now. return; } if (delete) deleteTextRange(offset, length, textWidget); } catch (BadLocationException x) { } finally { clipboard.dispose(); }
The principle idea to handle the case where the widget text matches the document region is really good. I added a workaround that takes this idea but with code different from comment 25. This makes copy/paste work again for all cases where the selection does not include folded code.
*** Bug 169143 has been marked as a duplicate of this bug. ***
*** Bug 196777 has been marked as a duplicate of this bug. ***
*** Bug 317296 has been marked as a duplicate of this bug. ***
*** Bug 365305 has been marked as a duplicate of this bug. ***
*** Bug 414682 has been marked as a duplicate of this bug. ***
I hope I am in the right area. I too was having this problem and find I cannot copy and paste into word with colors. Eclipse: Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 2 Build id: 20130225-0426 Word 2007 BUT I found that I have set up a custom format Project > Properties > Java Code Style > Formatter. And after right clicking on my code > source > format The copy to word with color works. Obviously there is code in that block that is missing from the default editor. If you wish me to print out my settings, let me know where the log or config file is for theh Java Code Style Formatter and I will past it here. Hope this helps.
I just tried this with platform version 4.3.2 of eclipse (eclipse JDT version 3.9.2), and the bug still persists. The problem for users is that it is not intuitive that rtf-copying should work only when no code is folded. Most users would look for the problem at the receiving (paste) side. I really don´t care about the color formatting of the folded part, but the unfolded part should be correct, or at least could the RTF clipboard exist and contain a warning about this bug.
Created attachment 247297 [details] Fix (In reply to Dani Megert from comment #26) > This makes copy/paste work again for all cases where the selection does not > include folded code. We should just use textWidget.copy() in all cases. If there are collapsed foldings, we have to expand them temporarily. The fix could add setRedraw(false/true), but it think the slight flickering is actually interesting, since it tells the user that something's going on behind the scenes.
Comment on attachment 247297 [details] Fix (In reply to Markus Keller from comment #35) > Created attachment 247297 [details] [diff] > Fix > > (In reply to Dani Megert from comment #26) > > This makes copy/paste work again for all cases where the selection does not > > include folded code. > > We should just use textWidget.copy() in all cases. If there are collapsed > foldings, we have to expand them temporarily. The fix could add > setRedraw(false/true), but it think the slight flickering is actually > interesting, since it tells the user that something's going on behind the > scenes. The flickering is too intrusive and it is also visible in the overview ruler.
Back to inbox, then. Calling setRedraw(false/true) before/after modifying the annotations also stops updates to the text widget and effectively blocks the fix.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
The problem still persists in eclipse 2022-09. There is still no indication to the user that copy works differently depending whether code is collapsed or not.