Patch #3449 2013-04-01 12:13

kalith

"Toggle comment": do not mix un/comment
Download
3449-Toggle_comment.patch (1.5 KB)
Category
Application::Refinement
Status
Accepted
Close date
2013-04-17 00:32
Assigned to
alpha0010
--- 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 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();