Repository navigation
Description
When StyledText saves HTML to clipboard and the result is pasted into some application, in some cases the multiple spaces are collapsed into one.
This happens in GMail, MS Word, and Powerpoint.
The spaces are preserved in Google Docs and Google Slides.
This is most obvious for code, which needs indent.
To Reproduce
Run this code in Eclipse:
public class Main {
public static void main(String[] args) {
System.out.println("\033[31mpublic class\033[m Main {");
System.out.println(" \033[31mpublic static void\033[m main(String[] args) {");
System.out.println(" \033[32m// TODO Auto-generated method stub\033[m");
System.out.println(" System.\033[34mout\033[m.println(\033[34m\"Hello world!\"\033[m);");
System.out.println(" }");
System.out.println("}");
}
}
The console should look like syntax colored "Hello world" app.
Select the text in console and copy to clipboard. You can use Ctrl+Insert in Win / Linux (Option+Insert on Mac) to copy without escape codes.
Paste the clipboard content in Gmail (create new email), or in MS Word / MS PowerPoint.
Expected behavior
The spaces should be preserved, the result when pasted into an application should look as close as possible to what we see in the StyledText (for example in Eclipse).
Screenshots
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
- Additional OS info (e.g. OS version, Linux Desktop, etc)
Tried on Win 11, MacOS, Debian
- JRE/JDK version
11, but very likely not relevant.
Version since
Eclipse 2022-12 M3 (4.26.0 M3)
HTML was not available as clipboard format until recently (Sep 19, 2022)
This was discovered while testing eclipse-jdt/eclipse.jdt.ui#320.
Before it was harder to notice because I did not copy-paste text with multiple spaces, which is more common in code.
Workaround (or) Additional context
No workarounds.
But the cause is easy to see if we dump the clipboard and inspect the HTML (or look at the code).
The div wrapping the content specifies style=' ... white-space:nowrap;'
But white-space:nowrap "collapses white space as for normal, but suppresses line breaks (text wrapping) within the source."
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
Need to use white-space:pre
"Sequences of white space are preserved. Lines are only broken at newline characters in the source and at <br> elements."

Activity