eclipse.platform.ui icon indicating copy to clipboard operation
eclipse.platform.ui copied to clipboard

Show ZWSP (zero with space) as code mining

Open marcushoepfner opened this issue 2 years ago • 12 comments

Issue: https://github.com/eclipse-platform/eclipse.platform.ui/issues/1002

For more information refer to https://www.compart.com/en/unicode/U+200B To get a ZWSP refer to https://zerowidthspace.me/

marcushoepfner avatar Dec 19 '23 15:12 marcushoepfner

Test Results

0 files   -  3 018  0 suites   - 3 018   0s ⏱️ - 2h 13m 29s 0 tests  -  8 226  0 ✅  -  7 977  0 💤  - 249  0 ❌ ±0  0 runs   - 23 598  0 ✅  - 22 804  0 💤  - 794  0 ❌ ±0 

Results for commit c97d0b4b. ± Comparison against base commit 875996f4.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Dec 19 '23 16:12 github-actions[bot]

I did a quick manual test on macOS. I found the following issues:

  1. code mining is not displayed emidiately. I have to close and reopen the editor for the code minings to be shown

  2. Two ZWSP next to each other are drawn one the (almost?) same location. See line 4 in: image

  3. When select the "a" and the "ZWSP" in line 2 from the above screenshot to with the keyboard I have to press the right-cursor two times until the caret is behind the "ZWSP".

BeckerWdf avatar Dec 20 '23 07:12 BeckerWdf

I manually tested your change.

the ZWSP is shown correctly: image

but when I disable the "show whitespace character" function (e.g. via the toolbar button) the ZWSP code mining still not disappears (even though the other "white space character" stuff does correctly disappear: image

BeckerWdf avatar Aug 13 '25 07:08 BeckerWdf

another topic: a user can change the color of the code minings in the "fonts and colors" preference page. If you do this you will see a mix of colors:

image

Maybe this can be improved:

  • either by ignoring the users color pref here
  • also use the code mining color from preferences for the other "white space character" drawing logic.

BeckerWdf avatar Aug 13 '25 07:08 BeckerWdf

I manually tested your change.

the ZWSP is shown correctly: image

but when I disable the "show whitespace character" function (e.g. via the toolbar button) the ZWSP code mining still not disappears (even though the other "white space character" stuff does correctly disappear: image

fixed with the last commit.

marcushoepfner avatar Oct 09 '25 13:10 marcushoepfner

another topic: a user can change the color of the code minings in the "fonts and colors" preference page. If you do this you will see a mix of colors:

image Maybe this can be improved:
  • either by ignoring the users color pref here
  • also use the code mining color from preferences for the other "white space character" drawing logic.

I tried to ignore and overwrite the color with the one TextEditor uses for drawing spaces, tabs,... According to https://github.com/eclipse-platform/eclipse.platform.ui/blob/2c5b6056f00e7a012022aa8f5342ed5f97e5a6c1/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/WhitespaceCharacterPainter.java#L447 this is SWT.COLOR_LIST_FOREGROUND, which is black. I even debugged the drawing of a tab and it was colored 0, 0, 0 but appeared grey. I dont get it....

marcushoepfner avatar Oct 09 '25 13:10 marcushoepfner

I just played around a bit with the current state. I got this:

java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.widgets.Display.getSystemColor(int)" because the return value of "org.eclipse.swt.widgets.Display.getCurrent()" is null
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMining.<init>(ZeroWidthCharactersLineContentCodeMining.java:40)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.createCodeMining(ZeroWidthCharactersLineContentCodeMiningProvider.java:108)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.provideCodeMinings(ZeroWidthCharactersLineContentCodeMiningProvider.java:72)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$2(CodeMiningManager.java:194)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

BeckerWdf avatar Oct 10 '25 14:10 BeckerWdf

fixed with the last commit.

Thanks. That looks good now.

BeckerWdf avatar Oct 13 '25 05:10 BeckerWdf

I just played around a bit with the current state. I got this:

java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.widgets.Display.getSystemColor(int)" because the return value of "org.eclipse.swt.widgets.Display.getCurrent()" is null
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMining.<init>(ZeroWidthCharactersLineContentCodeMining.java:40)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.createCodeMining(ZeroWidthCharactersLineContentCodeMiningProvider.java:108)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.provideCodeMinings(ZeroWidthCharactersLineContentCodeMiningProvider.java:72)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$2(CodeMiningManager.java:194)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

This is now also fixed. Thanks,

BeckerWdf avatar Oct 13 '25 05:10 BeckerWdf

I just played around a bit with the current state. I got this:

java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.widgets.Display.getSystemColor(int)" because the return value of "org.eclipse.swt.widgets.Display.getCurrent()" is null
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMining.<init>(ZeroWidthCharactersLineContentCodeMining.java:40)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.createCodeMining(ZeroWidthCharactersLineContentCodeMiningProvider.java:108)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.provideCodeMinings(ZeroWidthCharactersLineContentCodeMiningProvider.java:72)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$2(CodeMiningManager.java:194)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

This is now also fixed. Thanks,

Is the color of "ZWSP" grey or black in your case?

marcushoepfner avatar Oct 13 '25 05:10 marcushoepfner

I tried to ignore and overwrite the color with the one TextEditor uses for drawing spaces, tabs,... According to

https://github.com/eclipse-platform/eclipse.platform.ui/blob/2c5b6056f00e7a012022aa8f5342ed5f97e5a6c1/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/WhitespaceCharacterPainter.java#L447

this is SWT.COLOR_LIST_FOREGROUND, which is black. I even debugged the drawing of a tab and it was colored 0, 0, 0 but appeared grey. I dont get it....

I also just debugged this. And I see that the color (for the whitespace chars comes from the styleRange not the textWidget:

https://github.com/eclipse-platform/eclipse.platform.ui/blob/2c5b6056f00e7a012022aa8f5342ed5f97e5a6c1/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/WhitespaceCharacterPainter.java#L449

BeckerWdf avatar Oct 13 '25 05:10 BeckerWdf

Is the color of "ZWSP" grey or black in your case?

black.

BeckerWdf avatar Oct 13 '25 05:10 BeckerWdf