Community
Participate
Working Groups
The bug can be explored using the Java Editor or the C Editor: Select a region, where the last line of the selection is an empty line, that does not even contain spaces or tabs. Using 'Toggle Comment' the last line of the selection is not commented. Using 'Toggle Comment' again the region is not uncommented, rather than that additional comments are added. The reason for the behavior is that 'TextViewer.shift(...)' adjusts the selection via TextViewer.getTextBlockFromSelection(..), which drops the last line. The decision whether commenting or uncommenting has to be performed is done in the class ToggleCommentAction, which does check the last line. While the fix could be done in ToggleCommentAction (of JDT and CDT), to me it looks like TextViewer.shift(..) is the faulty part.
Created attachment 179021 [details] fix
Thanks for tracking this down Markus. The patch goes into the right direction though I don't like coding by exception too much. Can you please handle that case in regular code and also add your credentials to the copyright notice of the file in the following form: name <e-mail> - bugzilla summary - bugzilla URL e.g. Dani Megert <dani@eclipse.org> - this is a bug - https://bugs.eclipse.org... Thanks!
Created attachment 179040 [details] updated fix The new patch no longer relies on a caught exception. In addition to that I have removed the outer catch clause in getTextBlockFromSelection(..), because returning 'null' would just trigger a NPE in the calling method, whereas the BadLocationException is handled there. If you don't like it that way feel free to adjust my patch before applying it.
(In reply to comment #3) > In addition to that I > have removed the outer catch clause in getTextBlockFromSelection(..), because > returning 'null' would just trigger a NPE in the calling method, whereas the > BadLocationException is handled there. Good catch! Patch committed to HEAD. Available in builds > N20100917-2000.
>Available in builds > N20100917-2000. Available in builds >= N20100917-2000.
Thanks, I have verified the fix with the CDT editor using 3.7M3.