eclipse-platform/eclipse.platform.text

The Java code editor does not save HTML to Clipboard

mihnita opened this issue · 6 comments

Tested with the 2022-10-13 nightly build (eclipse-SDK-I20221013-1800-win32-x86_64.zip)
Created a small "Hello world" Java app.
Selected the code and copied it to the clipboard.
It does not matter if I do it from the main menu (Edit -- Copy), the context menu (right-click, Copy) or hotkey (Ctrl+C), the result is the same.
The clipboard contains RTF, but not HTML.


My hope was that all editors (based on StyledText) will "just work"
Apparently that is not the case, some still do some custom processing and need fixing.

I will continue to test the most common editors in the next few days (C/C++, Python, .properties, XML, pom.xml, html?)

Do you happen to know what would be a good source of information on what formats are most popular?
Based on real data, not my gut feeling? :-)


Please assign this to me.

Thanks,
Mihai

I suspect the ProjectionViewer, that does wrap the StyledText and add support for folding ranges, does override the Copy Action without fully delegating to StyledText.

Thank you!

Looking at the code in ProjectionViewer.java it looks like it tries to copy non-styled text.
But I can't tell if it is intentional:

String copyText= selection.getText();
if (copyText == null)
	textWidget.copy();

if (copyText != null && copyText.equals(textWidget.getSelectionText())) {
	textWidget.copy();
} else if (copyText != null) {
	// Custom copy, TextTransfer only
}

So in two cases it just calls textWidget.copy();, and that would work.


From all I understand the last case (where copyText differs from textWidget.getSelectionText()) happens when one tries to copy a folded section.

And that does not seem to have style info in the text copied in that case.
copyText is a String, coming from an ITextSelection

String copyText= selection.getText();

I've also checked the current Eclipse functionality, and seems to confirm it.
When I copy a method, the clipboard contains RTF format, but if I try to copy a folded method there is no RTF format, just plain text.
And it is the unfolded text, so not WYSIWYG (I see a folded method, I copy-paste the unfolded one).


TLDR: I don't think I can fix that now.
If it need changing, then it is a bigger refactoring / feature request ("copy folded code with syntax highlighting")

Meantime I've created 2 PRs:


What I also did: took my day-to-day Eclipse install, with all the plugins, unpacked everything (all the .zip and .jar files), then searched in all the .class files for references to RTFTransfer and RTFWriter.
On the idea that if they use that, they probably care about styled text, so they would also want HTMLTransfer and HTMLWriter.

And I've only found the JDT and PDE code that I am changing in the above PRs (and of course the SWT and ANSI console, which are already fixed).

I know it can't possibly cover everything, but it is would hopefully cover the most popular plugins?
(I have installed support for Java, Maven, Plugin development, C/C++, Web, XML, XSL, Javascript, Javadoc, Git)


Should I send a message to cross-project-issues-dev?
This sounds like a cross-project thing, and maybe owners of other projects will know if they are affected.
But I am not yet familiar with the customs :-)

Thank you,
Mihai

@mihnita is this one closed? The JDT commit is merged and the rest of your PR is seems closed.

Sorry for the delay (holidays, vacation, a flu, and jury duty, one on top of the other).

Yes, it's closed, thank you for the reminder,
Mihai