Bug 64498 - [projection] Clipboard Copy & Paste: No color and font information (RTF) with collapsed folding section
Summary: [projection] Clipboard Copy & Paste: No color and font information (RTF) with...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows NT
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 65373 66088 66283 66818 75009 76443 78518 108279 169143 196777 317296 365305 414682 (view as bug list)
Depends on: 106822
Blocks:
  Show dependency tree
 
Reported: 2004-05-28 03:41 EDT by Dirk Grossmann CLA
Modified: 2022-12-24 07:00 EST (History)
27 users (show)

See Also:


Attachments
Fix (2.72 KB, patch)
2014-09-23 08:44 EDT, Markus Keller CLA
daniel_megert: review-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Grossmann CLA 2004-05-28 03:41:50 EDT
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.
Comment 1 Grant Gayed CLA 2004-05-28 10:14:38 EDT
FH has something changed in StyledText$RTFWriter?
Comment 2 Veronika Irvine CLA 2004-05-28 10:28:01 EDT
Works on Windows XP - will try on Windows NT.
Comment 3 Veronika Irvine CLA 2004-05-28 13:21:47 EDT
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)
Comment 4 Veronika Irvine CLA 2004-05-28 13:33:51 EDT
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
Comment 5 Veronika Irvine CLA 2004-05-28 14:49:04 EDT
Sorry, ignore comment #4 - code takes a different path whether "Update imports 
on paste" is turned on in preferences
Comment 6 Veronika Irvine CLA 2004-05-28 14:49:37 EDT
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)
Comment 7 Veronika Irvine CLA 2004-05-28 14:51:27 EDT
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?).
Comment 8 Kai-Uwe Maetzel CLA 2004-06-03 06:12:06 EDT
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.
Comment 9 Kai-Uwe Maetzel CLA 2004-06-03 13:41:43 EDT
*** Bug 65373 has been marked as a duplicate of this bug. ***
Comment 10 Ed Burnette CLA 2004-06-07 17:26:26 EDT
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.
Comment 11 Dani Megert CLA 2004-06-14 04:14:09 EDT
*** Bug 66818 has been marked as a duplicate of this bug. ***
Comment 12 Dani Megert CLA 2004-06-14 04:14:17 EDT
*** Bug 66088 has been marked as a duplicate of this bug. ***
Comment 13 Dani Megert CLA 2004-06-15 12:24:04 EDT
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.

Comment 14 Dani Megert CLA 2004-06-15 12:35:08 EDT
*** Bug 66283 has been marked as a duplicate of this bug. ***
Comment 15 Dani Megert CLA 2004-07-13 09:41:54 EDT

*** This bug has been marked as a duplicate of 59459 ***
Comment 16 Dani Megert CLA 2004-07-13 09:43:34 EDT
closed wrong bug as dup
Comment 17 Dani Megert CLA 2004-09-27 09:37:09 EDT
*** Bug 75009 has been marked as a duplicate of this bug. ***
Comment 18 Dani Megert CLA 2004-10-18 05:08:13 EDT
*** Bug 76443 has been marked as a duplicate of this bug. ***
Comment 19 Dani Megert CLA 2004-11-12 11:33:25 EST
*** Bug 78518 has been marked as a duplicate of this bug. ***
Comment 20 Carolyn MacLeod CLA 2004-11-12 12:54:46 EST
I just added a comment to bug 65645. If you agree with the comment, please say 
so in that bug.
Comment 21 Peter Kidson CLA 2005-03-31 10:33:09 EST
Same problem with 3.1M5a

W2K, copying from Eclipse Java source to programmer documentation in Word.

Comment 22 Peter Kidson CLA 2005-04-25 06:30:25 EDT
Does it with .java files,  but not with .txt files.
Comment 23 Carolyn MacLeod CLA 2005-04-26 02:14:53 EDT
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
Comment 24 Dani Megert CLA 2005-08-30 04:03:48 EDT
*** Bug 108279 has been marked as a duplicate of this bug. ***
Comment 25 Christopher Oezbek CLA 2006-03-14 07:37:28 EST
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();
}
Comment 26 Dani Megert CLA 2006-03-14 11:35:05 EST
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.
Comment 27 Dani Megert CLA 2006-12-30 03:58:13 EST
*** Bug 169143 has been marked as a duplicate of this bug. ***
Comment 28 Dani Megert CLA 2007-07-17 04:59:11 EDT
*** Bug 196777 has been marked as a duplicate of this bug. ***
Comment 29 Dani Megert CLA 2010-06-18 10:09:51 EDT
*** Bug 317296 has been marked as a duplicate of this bug. ***
Comment 30 Markus Keller CLA 2011-12-01 13:40:31 EST
*** Bug 365305 has been marked as a duplicate of this bug. ***
Comment 31 Dani Megert CLA 2013-08-08 16:23:23 EDT
*** Bug 414682 has been marked as a duplicate of this bug. ***
Comment 32 Richard Kaufman CLA 2014-04-01 21:24:52 EDT
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.
Comment 33 Richard Kaufman CLA 2014-04-01 21:25:19 EDT
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.
Comment 34 J. Weimar CLA 2014-09-23 05:39:14 EDT
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.
Comment 35 Markus Keller CLA 2014-09-23 08:44:55 EDT
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 36 Dani Megert CLA 2014-10-23 07:49:45 EDT
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.
Comment 37 Markus Keller CLA 2014-11-04 08:51:54 EST
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.
Comment 38 Eclipse Genie CLA 2020-09-29 01:06:02 EDT
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.
Comment 39 Eclipse Genie CLA 2022-12-24 02:12:15 EST
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.
Comment 40 J. Weimar CLA 2022-12-24 07:00:13 EST
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.