Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 323456

Summary: Uncomment code separated by empty lines
Product: [Tools] CDT Reporter: Marc-André Laperle <malaperle>
Component: cdt-editorAssignee: Anton Leherbauer <aleherb+eclipse>
Status: RESOLVED FIXED QA Contact: Anton Leherbauer <aleherb+eclipse>
Severity: normal    
Priority: P3 CC: yevshif
Version: 7.0   
Target Milestone: 8.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Toggle Comment Empty line patch
none
Toggle Comment Empty line patch 2 aleherb+eclipse: iplog+

Description Marc-André Laperle CLA 2010-08-23 23:08:08 EDT
Created attachment 177279 [details]
Toggle Comment Empty line patch

Example:

//foo

//bar

Selecting the three lines and using "Toggle Comment" will result in 

////foo
//
////bar

I think it should instead remove the comments.
Comment 1 Anton Leherbauer CLA 2010-08-24 05:26:43 EDT
Two suggestions:
- use text.trim().length() == 0 instead of the regular expression.
- move the test for empty lines before the TextUtilities.indexOf()

The method should also not return true when the region contains only empty lines.
Comment 2 Marc-André Laperle CLA 2010-08-24 23:01:43 EDT
Created attachment 177382 [details]
Toggle Comment Empty line patch 2

Thanks for the suggestions.
Comment 3 Anton Leherbauer CLA 2010-08-26 03:42:34 EDT
It is now no longer possible to add comments to a block of empty lines.  There is no need for a method isBlockEmpty().  Just make sure isBlockCommented() does not return true when the selection contains only empty lines.
I also don't understand the special case i != endLine in isBlockCommented().

While testing this I found a strange behavior: 
If the last line in the selection is completely empty (no space, etc.) it is _not_ commented.  The same behavior shows the Java Editor which makes me think it is a platform issue in TextViewer.shift().

BTW, it would be good to have a few JUnit tests for this feature.  You could take the AddBlockCommentTest as a boilerplate.
Comment 4 Anton Leherbauer CLA 2010-10-13 09:25:16 EDT
I committed the last patch with a few modifications to re-enable commenting of empty lines.
Comment 5 CDT Genie CLA 2010-10-13 10:23:05 EDT
*** cdt cvs genie on behalf of aleherbau ***
Bug 323456 - Uncomment code separated by empty lines
Patch from Marc-Andre Laperle

[*] ToggleCommentAction.java 1.16 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleCommentAction.java?root=Tools_Project&r1=1.15&r2=1.16