Skip to content

Conversation

@marcushoepfner
Copy link
Contributor

Issue: #1002

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 19, 2023

Test Results

0 files   -  3 018  0 suites   - 3 018   0s ⏱️ - 2h 14m 57s
0 tests  -  8 229  0 ✅  -  7 981  0 💤  - 248  0 ❌ ±0 
0 runs   - 23 511  0 ✅  - 22 720  0 💤  - 791  0 ❌ ±0 

Results for commit d7f2584. ± Comparison against base commit 34bb179.

♻️ This comment has been updated with latest results.

@BeckerWdf
Copy link
Member

BeckerWdf commented Dec 20, 2023

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
  1. 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".


public class ZeroWidthSpaceLineContentCodeMiningProvider extends AbstractCodeMiningProvider {

private static final char ZWSP_SIGN = '\u200b';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also add

\u200c  zero width non-joiner
\u200d  zero width joiner
\ufeff  zero width no break space

See: https://plugins.jetbrains.com/plugin/7448-zero-width-characters-locator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this PR.
It works now with all above zero width characters.

Please check it.
Please also check the new preferences:
image

  1. Do we need to distinguish between line begin, end and enclosing for ZWSP? IMHO not, just makes core more complex. But "enclosing" may not fit as a term then.

  2. Do we show ZWSP as code mining or something else? Because it is not just space.

image

@marcushoepfner marcushoepfner force-pushed the zwsp branch 4 times, most recently from b082ac8 to 6cccc08 Compare August 5, 2025 14:06
@marcushoepfner marcushoepfner marked this pull request as draft August 6, 2025 06:21
@marcushoepfner marcushoepfner marked this pull request as ready for review August 13, 2025 06:35
@BeckerWdf
Copy link
Member

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

Copy link
Member

@BeckerWdf BeckerWdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments above

@BeckerWdf
Copy link
Member

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.

@marcushoepfner
Copy link
Contributor Author

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
Copy link
Contributor Author

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

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 marcushoepfner force-pushed the zwsp branch 3 times, most recently from 0ee781a to 8b2948b Compare October 9, 2025 13:27
@BeckerWdf
Copy link
Member

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)

@marcushoepfner marcushoepfner marked this pull request as draft October 13, 2025 05:20
@BeckerWdf
Copy link
Member

fixed with the last commit.

Thanks. That looks good now.

@BeckerWdf
Copy link
Member

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,

@marcushoepfner
Copy link
Contributor Author

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?

@BeckerWdf
Copy link
Member

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

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:

@BeckerWdf
Copy link
Member

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

black.

@tobiasmelcher
Copy link
Contributor

The WhitespaceCharacterPainter uses in the light theme the black color Color {0, 0, 0, 255} to draw the invisible characters with gc.drawString. It looks greyish because gc.setAlpha(fAlpha); is called beforehand with value fAlpha=80.
Here the location where setAlpha is called.

private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
		int startLine= fTextWidget.getLineIndex(y);
		int endLine= fTextWidget.getLineIndex(y + h - 1);
		if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {

			// avoid painting into the margins:
			Rectangle clipping= gc.getClipping();
			Rectangle clientArea= fTextWidget.getClientArea();
			int leftMargin= fTextWidget.getLeftMargin();
			int rightMargin= fTextWidget.getRightMargin();
			clientArea.x+= leftMargin;
			clientArea.width-= leftMargin + rightMargin;
			clipping.intersect(clientArea);
			gc.setClipping(clientArea);
			if (fIsAdvancedGraphicsPresent) {
				int alpha= gc.getAlpha();
				gc.setAlpha(fAlpha); // <!------------------------------------
				drawLineRange(gc, startLine, endLine, x, w);
				gc.setAlpha(alpha);
			} else {
				drawLineRange(gc, startLine, endLine, x, w);
			}
			gc.setClipping(clipping);
		}
	}

We could do the same in the ZeroWidthCharactersLineContentCodeMining so that all whitespaces are rendered in the same color. Maybe introduce a re-usable in WhitespaceCharacterPainter to retrieve the color config which can then be reused by the code mining.

@tobiasmelcher
Copy link
Contributor

​[c5d21c1] sets the same color in the ZWSP code minings as it is done in the whitespace character painter

image

@tobiasmelcher
Copy link
Contributor

Unfortunately, the rendering on Windows does currently not look that good compared to MacOS (all screenshots shown above are from MacOS).

Here a Windows screenshot with font Consolas. There is an unwanted gap between ZWSP and the next character.

zwsp_windows_consolas

And here a Windows screenshot with font Courier New. The additional width required for the ZWSP code mining is somehow not taken into account.

zwsp_windows_courier_new

@tobiasmelcher
Copy link
Contributor

[b76e3d4] solves the rendering problem on windows.

Here a screenshot with the Consolas font on Windows showing the zero width spaces as code minings.
image

Here a screenshot with the Courier New font on Windows showing the zero width spaces as code minings.
image

Here a screenshot with the Monospace font on Linux (Suse) showing the zero width spaces as code minings.
image

@BeckerWdf
Copy link
Member

[b76e3d4] solves the rendering problem on windows.

Does it make sense to extract this to an own PR. I assume that we could reproduce this error without this new feature in the whitespace drawer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants