QScintilla/Editor.py

branch
5_3_x
changeset 2495
33cbc28c3ba9
parent 2491
c6e2c7b1a52e
child 2518
1697fb3ad2d6
--- a/QScintilla/Editor.py	Fri Mar 15 18:25:30 2013 +0100
+++ b/QScintilla/Editor.py	Sat Mar 16 11:48:07 2013 +0100
@@ -3164,7 +3164,21 @@
     ############################################################################
     ## Comment handling methods below
     ############################################################################
-
+    
+    def __isCommentedLine(self, line, commentStr):
+        """
+        Private method to check, if the given line is a comment line as produced
+        by the configured comment rules.
+        
+        @param line text of the line to check (string)
+        @param commentStr comment string to check against (string)
+        @return flag indicating a commented line (boolean)
+        """
+        if Preferences.getEditor("CommentColumn0"):
+            return line.startswith(commentStr)
+        else:
+            return line.strip().startswith(commentStr)
+    
     def toggleCommentBlock(self):
         """
         Public slot to toggle the comment of a block.
@@ -3182,22 +3196,22 @@
         # check if line starts with our comment string (i.e. was commented
         # by our comment...() slots
         if self.hasSelectedText() and \
-           self.text(self.getSelection()[0]).strip().startswith(commentStr):
+           self.__isCommentedLine(self.text(self.getSelection()[0]), commentStr):
             self.uncommentLineOrSelection()
-        elif not self.text(line).strip().startswith(commentStr):
+        elif not self.__isCommentedLine(self.text(line), commentStr):
             # it doesn't, so comment the line or selection
             self.commentLineOrSelection()
         else:
             # determine the start of the comment block
             begline = line
             while begline > 0 and \
-                  self.text(begline - 1).strip().startswith(commentStr):
+                  self.__isCommentedLine(self.text(begline - 1), commentStr):
                 begline -= 1
             # determine the end of the comment block
             endline = line
             lines = self.lines()
             while endline < lines and \
-                  self.text(endline + 1).strip().startswith(commentStr):
+                  self.__isCommentedLine(self.text(endline + 1), commentStr):
                 endline += 1
             
             self.setSelection(begline, 0, endline, self.lineLength(endline))
@@ -3233,7 +3247,7 @@
         
         # check if line starts with our comment string (i.e. was commented
         # by our comment...() slots
-        if not self.text(line).strip().startswith(commentStr):
+        if not self.__isCommentedLine(self.text(line), commentStr):
             return
         
         # now remove the comment string
@@ -3301,7 +3315,7 @@
         for line in range(lineFrom, endLine + 1):
             # check if line starts with our comment string (i.e. was commented
             # by our comment...() slots
-            if not self.text(line).strip().startswith(commentStr):
+            if not self.__isCommentedLine(self.text(line), commentStr):
                 continue
             
             if Preferences.getEditor("CommentColumn0"):

eric ide

mercurial