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

"Show whitespace" should also show "Zero Width Whitepace"

Open BeckerWdf opened this issue 2 years ago • 17 comments

Source Code (that e.g. was copied from a web page) might contain zero width whitespaces (ZWSP). That this is can be read here; https://en.wikipedia.org/wiki/Zero-width_space#:~:text=The%20zero%2Dwidth%20space%20(%E2%80%8B,but%20after%20which%20there%20may

The "Show Whiteplace" function of the text editor does show whitespaces and line breaks etc. but does not show ZWSPs.

Other editor (e.g. Notepad++ on windows) can show this. See: telegram-cloud-photo-size-2-5379835439394965993-m

I think eclipse should also be capable of showing this.

If you are asking how to enter an ZWSP into your editor: Use this website: https://zerowidthspace.me/

BeckerWdf avatar Aug 10 '23 13:08 BeckerWdf

This was already proposed in https://bugs.eclipse.org/bugs/show_bug.cgi?id=578213

BeckerWdf avatar Aug 11 '23 05:08 BeckerWdf

org.eclipse.jface.text.WhitespaceCharacterPainter is the place where the whitespace char drawing happens

BeckerWdf avatar Aug 11 '23 08:08 BeckerWdf

This was already proposed in https://bugs.eclipse.org/bugs/show_bug.cgi?id=578213

Can this enhancement to show invisible characters be extended to all Zero width characters as mentioned here ?https://plugins.jetbrains.com/plugin/7448-zero-width-characters-locator

lathapatil avatar Oct 13 '23 08:10 lathapatil

Would you like to see this as an option here?

show_whitespace_characters

marcushoepfner avatar Oct 31 '23 14:10 marcushoepfner

Would you like to see this as an option here?

Yes. Ideally ZWSP proposed by author might come here . Along with this other Zero width characters can be implemented as part of this enhancement.

lathapatil avatar Nov 02 '23 05:11 lathapatil

The responsible java class is WhitespaceCharacterPainter (method drawCharRange). It seems, that it replaces one character by another, e.g. space by middle dot.

I tried to replace a zero with white space with the letters "ZWSP". But then it looks strange when I continue typing.

This is only the ZWSP pasted from https://zerowidthspace.me/ (it has a width of 0 of course). It looks ok: zwsp But when typing is continued, it looks strange: zwsp_typing_continued

marcushoepfner avatar Nov 07 '23 08:11 marcushoepfner

ZWSP is invisible space and I have pasted it between letter "e" and "." and Show whitespace characters is off in preferences.

zwsp_prefereneceOff

I tried to modify the code so that ZWSP is replaced with \u2588 , but it is drawn on next character as below.. when Show whitespace characters is on in preferences.

ZWSP_Preference_ON

Currently Eclipse is supporting all visible characters so that there is space and where new symbol can be drawn but for invisible characters there is no space to draw new symbol . For CR and LF , when text is read to load itself it is read as \r and \n so that it can be easily drawn in this place.

Should we push next available character to make space for it ? so that drawing happens on later stage.. But there are challenges on how to achieve this !

lathapatil avatar Nov 08 '23 04:11 lathapatil

Should we push next available character to make space for it ? so that drawing happens on later stage.. But there are challenges on how to achieve this !

How do other editors handle that challenges?

BeckerWdf avatar Nov 08 '23 07:11 BeckerWdf

Should we push next available character to make space for it ? so that drawing happens on later stage.

Maybe we could do it similar like it's done for the code mining. For code minings also content is drawn for which we need to make space in the editor. The difference is that for the code minings we need additional vertical space for the none-width chars we need additional horizontal space.

BeckerWdf avatar Dec 19 '23 06:12 BeckerWdf

The difference is that for the code minings we need additional vertical space for the none-width chars we need additional horizontal space.

That's not true. See for example InlinedAnnotationDemo.java from the jface examples. Here the strings "red:", "green:" and "blue:" are drawn inline into the text.

BeckerWdf avatar Dec 19 '23 07:12 BeckerWdf

The difference is that for the code minings we need additional vertical space for the none-width chars we need additional horizontal space.

That's not true. See for example InlinedAnnotationDemo.java from the jface examples. Here the strings "red:", "green:" and "blue:" are drawn inline into the text.

Support for this seems to be completely in jface not in SWT.

BeckerWdf avatar Dec 19 '23 07:12 BeckerWdf

I think you should indeed consider using InlinedAnnotation for the case of adding "artificial" content in a text line.

mickaelistria avatar Dec 19 '23 08:12 mickaelistria

I have create a first PR.

Some questions.

  1. Is the used plugin the correct sport for this?

  2. There is a white space character preference page, the question is, whether we should add ZWSP? In contradiction the white space pref page is about the show white space character functionality which is handled in org.eclipse.jface.text.WhitespaceCharacterPainter, but in my commit code mining is used. But currently there is not Code Mining preference page for text editors itself, just for java editors.

marcushoepfner avatar Dec 19 '23 15:12 marcushoepfner

I don't think a new pref is necessary. Relying on the exisying Show whitespaces is enough

mickaelistria avatar Dec 19 '23 16:12 mickaelistria

  1. There is a white space character preference page, the question is, whether we should add ZWSP?

I Would say yes.

In contradiction the white space pref page is about the show white space character functionality which is handled in org.eclipse.jface.text.WhitespaceCharacterPainter, but in my commit code mining is used. But currently there is not Code Mining preference page for text editors itself, just for java editors.

But isn't this just an implementation detail. From a user perspective I would say these settings belong together.

BeckerWdf avatar Dec 19 '23 16:12 BeckerWdf

I don't think a new pref is necessary. Relying on the exisying Show whitespaces is enough

Ah, the whitespace pref page is very detailed. Refer to https://github.com/eclipse-platform/eclipse.platform.ui/issues/1002#issuecomment-1787297264. So we can add a setting for ZWSP.

marcushoepfner avatar Dec 19 '23 16:12 marcushoepfner

Ah, the whitespace pref page is very detailed. Refer to #1002 (comment). So we can add a setting for ZWSP.

This preference page is located in org.eclipse.ui.editors. See; https://github.com/eclipse-platform/eclipse.platform.ui/blob/44efc1d09a56d4c83a5f529b64aee54a757394f9/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java#L408

org.eclipse.ui.editors today has a dependency to org.eclipse.ui.workbench.texteditor. I think with this PR we would add a circular dependency when org.eclipse.ui.workbench.texteditor accesses the preference store of org.eclipse.ui.editors.

Wouldn't it be easier to move the org.eclipse.ui.workbench.texteditor.codeMiningProviders extension to the plugin.xml of org.eclipse.ui.editors?

BeckerWdf avatar Dec 20 '23 07:12 BeckerWdf