Feature #5639 2013-04-01 12:01
kalith
"Toggle comment": do not mix un/comment
Sorry for this horrible title, but the character limit is ridiculous...
Currently, "toggle comment" acts on each of the selected lines individually. This is most often not the desired action. Indeed, one would rather wants to comment/uncomment a block of code as a whole.
My suggestion: the command should first detect if any of the selected lines are uncommented. If so, then comment out the whole selection (adding comment tags to the lines that were already commented too). Else, all the lines are commented: uncomment them (removing one comment tag on each line).
This allows codes like:
int i = 0; // This is a great integer int j = i;
to be commented as:
// int i = 0; // // This is a great integer // int j = i;
while the current version would produce:
// int i = 0; This is a great integer // int j = i;
which makes no sense.
- Category
- Interface
- Status
- Closed
- Close date
- 2013-04-26 02:57
- Assigned to
History
Untested patch, so you get the idea: --- main_base.cpp 2013-04-01 14:01:14 +0200 +++ main.cpp 2013-04-01 14:08:03 +0200 @@ -3525,16 +3525,31 @@ void MainFrame::OnEditToggleCommentSelec --endLine; } + bool doComment = false; while( curLine <= endLine ) { - // For each line: If it's commented, uncomment. Otherwise, comment. + // Check is any of the selected lines is commented wxString strLine = stc->GetLine( curLine ); int commentPos = strLine.Strip( wxString::leading ).Find( comment ); if ( -1 == commentPos || commentPos > 0 ) + { + // If at least one line is not commented, then comment out the whole selection, + // else uncomment it. + doComment = true; + break; + } + ++curLine; + } + + curLine = startLine; + while( curLine <= endLine ) + { + if ( doComment ) stc->InsertText( stc->PositionFromLine( curLine ), comment ); else { // we know the comment is there (maybe preceded by white space) + wxString strLine = stc->GetLine( curLine ); int Pos = strLine.Find(comment); int start = stc->PositionFromLine( curLine ) + Pos; int end = start + comment.Length();
Sorry for the mess, I have uploaded the patch here: https://developer.berlios.de/patch/index.php?func=detailpatch&patch_id=3449&group_id=5358
Patch 3449 is committed.