The soft word wrap feature is not enabled in the official Eclipse release but can be activated with my Word Wrap Feature plug-in. This raises the issue that the line numbering will not work properly as you can see on this screenshot:
After installing the fix the line numbering works flawlessly together with the word wrap plug-in:
Please refer to the install instructions on the word wrap plug-in project website.
The fix will override your current org.eclipse.jface.text plug-in on the next startup of Eclipse because it is newer than your previous one. If you left some editors open before you copied the file to your plugin folder the new one will not work immediately. Please close all editor tabs and open them again. Now it should work just fine. :-)
The line ruler is created within the Eclipse Platform Text feature. The modified class is called LineNumberRulerColumn and is located in the org.eclipse.jface.text plug-in. I played around with the class to see how it works and was able to implement a correct rendering of the line ruler with word wrap activated.
Take a look at the modified LineNumberRulerColumn.java. Three methods were edited and one was added which I will now explain in detail.
Line 777: doPaint(GC gc, ILineRange visibleLines)
This method is called when the line ruler is painted. Before I changed this method it simply rendered all visibleLines one after the other. I checked whether the given text widget has word wrap turned on and added after each wrapped line enough empty lines in the line ruler to compensate for the space a single line is covering now.
The variable fillerText holds the characters that are displayed in the additional lines and can be externalized. Usually this is a single whitespace character but it is also possible to display dots (see screenshot below) or other characters. (If the filler character will be hardcoded it would be easier just to remove the fillerText variable and write: final String filler = " ";
Line 871: paintLine(String lineText, int line, int y, int lineheight, GC gc, Display display)
This is the newly added method which enables displaying strings instead of simple integer numbers in the line number ruler column. It is necessary for rendering additional lines with arbitrary filler characters.
Line 853: paintLine(int line, int y, int lineheight, GC gc, Display display)
This method can be seen as specialized version of the aforementioned paintLine(String, int, int, int, GC, Display) method and has been replaced with a delegation to it.
Line 613: createControl(CompositeRuler parentRuler, Composite parentControl)
In this method I've added a listener that watches the toggle of word wrapping in the editor and refreshes the line ruler accordingly. This is necessary because as a result of toggling the line wrapping the user did not enter any text or sent a scroll request to the viewport that could force a repaint of the line ruler. The listener waits for resize events which will be fired on toggling the word wrap feature.
It would be awesome if my fix would make it into the official Eclipse release. Therefore I really appreciate any feedback from you to keep this fix free of bugs and problems. Probably you know people who might benefit from this work, so please tell them about it! :-)
Further development for classes in this area can be found in section of the closely related word wrap plug-in.
Feel free to contact me and tell me about suggestions, bug reports and comments in general. I really appreciate any feedback and it would be great to hear from you if my work has helped you. You can write in English or German.
E-Mail: flo () cdhq () de (Please add the necessary symbols)