Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323456 - Uncomment code separated by empty lines
Summary: Uncomment code separated by empty lines
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.0   Edit
Assignee: Anton Leherbauer CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-23 23:08 EDT by Marc-André Laperle CLA
Modified: 2010-10-13 10:23 EDT (History)
1 user (show)

See Also:


Attachments
Toggle Comment Empty line patch (943 bytes, patch)
2010-08-23 23:08 EDT, Marc-André Laperle CLA
no flags Details | Diff
Toggle Comment Empty line patch 2 (2.45 KB, patch)
2010-08-24 23:01 EDT, Marc-André Laperle CLA
aleherb+eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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