QScintilla/Editor.py

changeset 1500
6ce6deb421cf
parent 1491
985c5abc8226
child 1507
9225700cbff5
equal deleted inserted replaced
1499:b4d0457afb15 1500:6ce6deb421cf
2907 2907
2908 ############################################################################ 2908 ############################################################################
2909 ## Comment handling methods below 2909 ## Comment handling methods below
2910 ############################################################################ 2910 ############################################################################
2911 2911
2912 def toggleCommentBlock(self):
2913 """
2914 Public slot to toggle the comment of a block.
2915
2916 If the line of the cursor or the selection is not commented, it will
2917 be commented. If it is commented, the comment block will be removed.
2918 The later works independent of the current selection.
2919 """
2920 if self.lexer_ is None or not self.lexer_.canBlockComment():
2921 return
2922
2923 commentStr = self.lexer_.commentStr()
2924 line, index = self.getCursorPosition()
2925
2926 # check if line starts with our comment string (i.e. was commented
2927 # by our comment...() slots
2928 if not self.text(line).strip().startswith(commentStr):
2929 # it doesn't, so comment the line or selection
2930 self.commentLineOrSelection()
2931 else:
2932 # determine the start of the comment block
2933 begline = line
2934 while begline > 0 and \
2935 self.text(begline - 1).strip().startswith(commentStr):
2936 begline -= 1
2937 # determine the end of the comment block
2938 endline = line
2939 lines = self.lines()
2940 while endline < lines and \
2941 self.text(endline + 1).strip().startswith(commentStr):
2942 endline += 1
2943
2944 self.setSelection(begline, 0, endline, self.lineLength(endline))
2945 self.uncommentLineOrSelection()
2946
2947 # reset the cursor
2948 self.setCursorPosition(line, index - len(commentStr))
2949
2912 def commentLine(self): 2950 def commentLine(self):
2913 """ 2951 """
2914 Public slot to comment the current line. 2952 Public slot to comment the current line.
2915 """ 2953 """
2916 if self.lexer_ is None or not self.lexer_.canBlockComment(): 2954 if self.lexer_ is None or not self.lexer_.canBlockComment():

eric ide

mercurial