changeset 24288:ff890a84b43c

allow uncommenting in editor when line begins with whitespace (bug #52406) * file-editor-tab.cc (do_comment_selected_text): use a regular expression instead of only checking the beginning of the line for a comment string
author Torsten <mttl@mailbox.org>
date Tue, 21 Nov 2017 21:35:32 +0100
parents ad0ca13aa6e2
children 8612ab9fc564
files libgui/src/m-editor/file-editor-tab.cc
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Mon Nov 20 08:05:10 2017 -0500
+++ b/libgui/src/m-editor/file-editor-tab.cc	Tue Nov 21 21:35:32 2017 +0100
@@ -1463,6 +1463,9 @@
 file_editor_tab::do_comment_selected_text (bool comment)
 {
   QString comment_str = _edit_area->comment_string ();
+  QRegExp rxc = QRegExp ("^([ \\t]*)" + comment_str);
+  int len, lenc = comment_str.length ();
+
   _edit_area->beginUndoAction ();
 
   if (_edit_area->hasSelectedText ())
@@ -1480,9 +1483,10 @@
           else
             {
               QString line (_edit_area->text (i));
-              if (line.startsWith (comment_str))
+              if (line.contains (rxc))
                 {
-                  _edit_area->setSelection (i, 0, i, comment_str.length ());
+                  len = rxc.matchedLength ();
+                  _edit_area->setSelection (i, len-lenc, i, len);
                   _edit_area->removeSelectedText ();
                 }
             }
@@ -1500,9 +1504,10 @@
       else
         {
           QString line (_edit_area->text (cpline));
-          if (line.startsWith (comment_str))
+          if (line.contains (rxc))
             {
-              _edit_area->setSelection (cpline, 0, cpline, comment_str.length ());
+              len = rxc.matchedLength ();
+              _edit_area->setSelection (cpline, len-lenc, cpline, len);
               _edit_area->removeSelectedText ();
             }
         }