Editor eric7

Sat, 23 Oct 2021 12:19:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Oct 2021 12:19:47 +0200
branch
eric7
changeset 8713
c2a124c2ecbb
parent 8712
ce5d777ecfef
child 8714
85deb98a0a6c

Editor
- added support for 'multi cursor editing' (additional cursors with Meta+Alt+Left Click, Esc to end it)

docs/changelog file | annotate | diff | comparison | revisions
eric7/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric7/QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
eric7/QScintilla/QsciScintillaCompat.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Sat Oct 23 09:16:10 2021 +0200
+++ b/docs/changelog	Sat Oct 23 12:19:47 2021 +0200
@@ -19,6 +19,8 @@
      (Python only)
   -- added mouse button capability to perform undo/redo actions (Extra
      Buttons 1 and 2)
+  -- added support for 'multi cursor editing' (additional cursors with
+     Meta+Alt+Left Click, Esc to end it)
 - Find In Files
   -- integrated the dialog into the right sidebar
 - Help Viewer
--- a/eric7/QScintilla/Editor.py	Sat Oct 23 09:16:10 2021 +0200
+++ b/eric7/QScintilla/Editor.py	Sat Oct 23 12:19:47 2021 +0200
@@ -208,6 +208,8 @@
         self.setAttribute(Qt.WidgetAttribute.WA_KeyCompression)
         self.setUtf8(True)
         
+        self.enableMultiCursorSupport()
+        
         self.dbs = dbs
         self.taskViewer = tv
         self.__setFileName(fn)
@@ -7194,6 +7196,16 @@
         elif event.button() == Qt.MouseButton.XButton2:
             self.redo()
             event.accept()
+        elif (
+            event.button() == Qt.MouseButton.LeftButton and
+            bool(event.modifiers() & (
+                Qt.KeyboardModifier.MetaModifier |
+                Qt.KeyboardModifier.AltModifier
+            ))
+        ):
+            line, index = self.lineIndexFromPoint(event.pos())
+            self.addCursor(line, index)
+            event.accept()
         else:
             self.vm.eventFilter(self, event)
             super().mousePressEvent(event)
@@ -8472,6 +8484,8 @@
         ):
             evt.accept()
             self.__mouseClickHandlers[key][1](self)
+        else:
+            super().mouseReleaseEvent(evt)
     
     def setMouseClickHandler(self, name, modifiers, button, function):
         """
--- a/eric7/QScintilla/MiniEditor.py	Sat Oct 23 09:16:10 2021 +0200
+++ b/eric7/QScintilla/MiniEditor.py	Sat Oct 23 12:19:47 2021 +0200
@@ -70,6 +70,8 @@
         """
         super().__init__(parent)
         
+        self.enableMultiCursorSupport()
+        
         self.mw = parent
     
     def getFileName(self):
@@ -152,6 +154,16 @@
         elif event.button() == Qt.MouseButton.XButton2:
             self.redo()
             event.accept()
+        elif (
+            event.button() == Qt.MouseButton.LeftButton and
+            bool(event.modifiers() & (
+                Qt.KeyboardModifier.MetaModifier |
+                Qt.KeyboardModifier.AltModifier
+            ))
+        ):
+            line, index = self.lineIndexFromPoint(event.pos())
+            self.addCursor(line, index)
+            event.accept()
         else:
             super().mousePressEvent(event)
     
--- a/eric7/QScintilla/QsciScintillaCompat.py	Sat Oct 23 09:16:10 2021 +0200
+++ b/eric7/QScintilla/QsciScintillaCompat.py	Sat Oct 23 12:19:47 2021 +0200
@@ -660,6 +660,31 @@
             selections.append(self.getSelectionN(index))
         return selections
     
+    def addCursor(self, line, index):
+        """
+        Public method to add an additional cursor.
+        
+        @param line line number for the cursor
+        @type int
+        @param index index number for the cursor
+        @type int
+        """
+        pos = self.positionFromLineIndex(line, index)
+        
+        if self.getSelectionCount() == 0:
+            self.SendScintilla(QsciScintilla.SCI_SETSELECTION, pos, pos)
+        else:
+            self.SendScintilla(QsciScintilla.SCI_ADDSELECTION, pos, pos)
+    
+    def enableMultiCursorSupport(self):
+        """
+        Public method to enable support for multi cursor editing.
+        """
+        # typing should insert in all selections at the same time
+        self.SendScintilla(QsciScintilla.SCI_SETMULTIPLESELECTION, True)
+        self.SendScintilla(QsciScintilla.SCI_SETADDITIONALSELECTIONTYPING,
+                           True)
+    
     def setVirtualSpaceOptions(self, options):
         """
         Public method to set the virtual space usage options.
@@ -1623,33 +1648,6 @@
             else:
                 return string.encode("latin-1")
     
-    ###########################################################################
-    ## methods to implement workarounds for broken things
-    ###########################################################################
-    
-    def positionFromLineIndex(self, line, index):
-        """
-        Public method to convert line and index to an absolute position.
-        
-        @param line line number (integer)
-        @param index index number (integer)
-        @return absolute position in the editor (integer)
-        """
-        pos = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE, line)
-        return pos + index
-    
-    def lineIndexFromPosition(self, pos):
-        """
-        Public method to convert an absolute position to line and index.
-        
-        @param pos absolute position in the editor (integer)
-        @return tuple of line number (integer) and index number (integer)
-        """
-        lin = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, pos)
-        linpos = self.SendScintilla(
-            QsciScintilla.SCI_POSITIONFROMLINE, lin)
-        return lin, pos - linpos
-    
     #########################################################################
     ## Methods below are missing from QScintilla.
     #########################################################################
@@ -1687,6 +1685,20 @@
             """
             self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL)
     
+    if "lineIndexFromPoint" not in QsciScintilla.__dict__:
+        def lineIndexFromPoint(self, point):
+            """
+            Public method to convert a point to line and index.
+            
+            @param point point to be converted
+            @type QPoin
+            @return tuple containing the line number and index number
+            @rtype tuple of (int, int)
+            """
+            pos = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINT,
+                                     point.x(), point.y())
+            return self.lineIndexFromPosition(pos)
+    
 ##    #########################################################################
 ##    ## Methods below have been added to QScintilla starting with version 2.x.
 ##    #########################################################################

eric ide

mercurial