src/eric7/QScintilla/Editor.py

branch
eric7-maintenance
changeset 9371
1da8bc75946f
parent 9304
afbd61b99bf4
parent 9333
b0541ec21e51
child 9442
906485dcd210
--- a/src/eric7/QScintilla/Editor.py	Fri Sep 02 14:10:44 2022 +0200
+++ b/src/eric7/QScintilla/Editor.py	Sat Oct 01 13:06:10 2022 +0200
@@ -3924,9 +3924,10 @@
         """
         Public slot to toggle the comment of a block.
 
-        If the line of the cursor or the selection is not commented, it will
-        be commented. If it is commented, the comment block will be removed.
-        The later works independent of the current selection.
+        If the editor contains selected text and the start line is not commented, it
+        will be commented. Otherwise the selection will be un-commented. In case there
+        is no selected text and the current line is not commented, it will be commented.
+        If is commented, the comment block will be removed.
         """
         if self.lexer_ is None or not self.lexer_.canBlockComment():
             return
@@ -3934,23 +3935,26 @@
         commentStr = self.lexer_.commentStr()
         line, index = self.getCursorPosition()
 
-        # check if line starts with our comment string (i.e. was commented
-        # by our comment...() slots
-        if self.hasSelectedText() and self.__isCommentedLine(
-            self.text(self.getSelection()[0]), commentStr
-        ):
-            self.uncommentLineOrSelection()
+        if self.hasSelectedText():
+            # Check if the selection starts with our comment string (i.e. was commented
+            # by our comment...() slots.
+            if self.__isCommentedLine(self.text(self.getSelection()[0]), commentStr):
+                self.uncommentLineOrSelection()
+            else:
+                self.commentLineOrSelection()
         elif not self.__isCommentedLine(self.text(line), commentStr):
-            # it doesn't, so comment the line or selection
+            # No selected text and the current line does not start with our comment
+            # string, so comment the line.
             self.commentLineOrSelection()
         else:
-            # determine the start of the comment block
+            # Uncomment the comment block containing the current line.
+            # 1. determine the start of the comment block
             begline = line
             while begline > 0 and self.__isCommentedLine(
                 self.text(begline - 1), commentStr
             ):
                 begline -= 1
-            # determine the end of the comment block
+            # 2. determine the end of the comment block
             endline = line
             lines = self.lines()
             while endline < lines and self.__isCommentedLine(
@@ -3958,10 +3962,9 @@
             ):
                 endline += 1
 
+            # 3. uncomment the determined block and reset the cursor position
             self.setSelection(begline, 0, endline, self.lineLength(endline))
             self.uncommentLineOrSelection()
-
-            # reset the cursor
             self.setCursorPosition(line, index - len(commentStr))
 
     def commentLine(self):
@@ -7777,6 +7780,23 @@
             if text in matchingPairs:
                 self.delete()
 
+        elif (
+            cmd in (QsciScintilla.SCI_LOWERCASE, QsciScintilla.SCI_UPPERCASE)
+            and self.hasSelectedText()
+        ):
+            startLine, startIndex, endLine, _ = self.getSelection()
+            selectedText = self.selectedText()
+            replacementText = (
+                selectedText.upper()
+                if cmd == QsciScintilla.SCI_UPPERCASE
+                else selectedText.lower()
+            )
+            self.replaceSelectedText(replacementText)
+            self.setSelection(
+                startLine, startIndex, endLine, len(replacementText.splitlines()[-1])
+            )
+            return
+
         super().editorCommand(cmd)
 
     def __applyTemplate(self, templateName, language):

eric ide

mercurial