Editor, MiniEditor: added code to enclose the current selection by entering " or ' characters.

Sun, 06 Dec 2020 18:37:08 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 06 Dec 2020 18:37:08 +0100
changeset 7865
393b25ccb048
parent 7862
817ef8e0fa66
child 7866
c8be86d8f1b3

Editor, MiniEditor: added code to enclose the current selection by entering " or ' characters.
(grafted from 431e6816c60c4bb5f79ba6e1969ad187587668e6)

docs/changelog file | annotate | diff | comparison | revisions
eric6/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric6/QScintilla/MiniEditor.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Sun Dec 06 17:43:11 2020 +0100
+++ b/docs/changelog	Sun Dec 06 18:37:08 2020 +0100
@@ -1,5 +1,10 @@
 Change Log
 ----------
+Version 21.1:
+- bug fixes
+- Editor:
+  -- added code to enclose the current selection by entering " or ' characters
+
 Version 20.12.1:
 - bug fixes
 
--- a/eric6/QScintilla/Editor.py	Sun Dec 06 17:43:11 2020 +0100
+++ b/eric6/QScintilla/Editor.py	Sun Dec 06 18:37:08 2020 +0100
@@ -6935,12 +6935,23 @@
         """
         Protected method to handle the user input a key at a time.
         
-        @param ev key event (QKeyEvent)
+        @param ev key event
+        @type QKeyEvent
         """
         txt = ev.text()
         
         # See it is text to insert.
         if len(txt) and txt >= " ":
+            if txt in ('"', "'") and self.hasSelectedText():
+                sline, sindex, eline, eindex = self.getSelection()
+                replaceText = txt + self.selectedText() + txt
+                self.beginUndoAction()
+                self.replaceSelectedText(replaceText)
+                self.endUndoAction()
+                self.setSelection(sline, sindex + 1, eline, eindex + 1)
+                ev.accept()
+                return
+            
             super(Editor, self).keyPressEvent(ev)
         else:
             ev.ignore()
@@ -6954,7 +6965,8 @@
         assuming, that it is in the vicinity of the old position after the
         reread.
         
-        @param event the event object (QFocusEvent)
+        @param event the event object
+        @type QFocusEvent
         """
         self.recolor()
         self.vm.editActGrp.setEnabled(True)
@@ -7007,7 +7019,8 @@
         """
         Protected method called when the editor loses focus.
         
-        @param event the event object (QFocusEvent)
+        @param event the event object
+        @type QFocusEvent
         """
         self.vm.editorActGrp.setEnabled(False)
         self.setCaretWidth(0)
@@ -7024,7 +7037,8 @@
         other modes. This is to make the editor windows work nicer
         with the QWorkspace.
         
-        @param evt the event, that was generated (QEvent)
+        @param evt the event, that was generated
+        @type QEvent
         """
         if (
             evt.type() == QEvent.WindowStateChange and
@@ -7044,7 +7058,8 @@
         """
         Protected method to handle the mouse press event.
         
-        @param event the mouse press event (QMouseEvent)
+        @param event the mouse press event
+        @type QMouseEvent
         """
         self.vm.eventFilter(self, event)
         super(Editor, self).mousePressEvent(event)
@@ -7053,7 +7068,8 @@
         """
         Protected method to handle wheel events.
         
-        @param evt reference to the wheel event (QWheelEvent)
+        @param evt reference to the wheel event
+        @type QWheelEvent
         """
         delta = evt.angleDelta().y()
         if evt.modifiers() & Qt.ControlModifier:
@@ -7078,8 +7094,10 @@
         """
         Public method handling events.
         
-        @param evt reference to the event (QEvent)
-        @return flag indicating, if the event was handled (boolean)
+        @param evt reference to the event
+        @type QEvent
+        @return flag indicating, if the event was handled
+        @rtype bool
         """
         if evt.type() == QEvent.Gesture:
             self.gestureEvent(evt)
@@ -7091,7 +7109,8 @@
         """
         Protected method handling gesture events.
         
-        @param evt reference to the gesture event (QGestureEvent
+        @param evt reference to the gesture event
+        @type QGestureEvent
         """
         pinch = evt.gesture(Qt.PinchGesture)
         if pinch:
@@ -7113,7 +7132,8 @@
         """
         Protected method handling resize events.
         
-        @param evt reference to the resize event (QResizeEvent)
+        @param evt reference to the resize event
+        @type QResizeEvent
         """
         super(Editor, self).resizeEvent(evt)
         self.__markerMap.calculateGeometry()
@@ -7122,8 +7142,10 @@
         """
         Protected method handling event of the viewport.
         
-        @param evt reference to the event (QEvent)
-        @return flag indiating that the event was handled (boolean)
+        @param evt reference to the event
+        @type QEvent
+        @return flag indiating that the event was handled
+        @rtype bool
         """
         try:
             self.__markerMap.calculateGeometry()
--- a/eric6/QScintilla/MiniEditor.py	Sun Dec 06 17:43:11 2020 +0100
+++ b/eric6/QScintilla/MiniEditor.py	Sun Dec 06 18:37:08 2020 +0100
@@ -51,7 +51,8 @@
         """
         Constructor
         
-        @param parent parent widget (QWidget)
+        @param parent parent widget
+        @type QWidget
         """
         super(MiniScintilla, self).__init__(parent)
         
@@ -61,10 +62,36 @@
         """
         Public method to return the name of the file being displayed.
         
-        @return filename of the displayed file (string)
+        @return filename of the displayed file
+        @rtype str
         """
         return self.mw.getFileName()
     
+    def keyPressEvent(self, ev):
+        """
+        Protected method to handle the user input a key at a time.
+        
+        @param ev key event
+        @type QKeyEvent
+        """
+        txt = ev.text()
+        
+        # See it is text to insert.
+        if len(txt) and txt >= " ":
+            if txt in ('"', "'") and self.hasSelectedText():
+                sline, sindex, eline, eindex = self.getSelection()
+                replaceText = txt + self.selectedText() + txt
+                self.beginUndoAction()
+                self.replaceSelectedText(replaceText)
+                self.endUndoAction()
+                self.setSelection(sline, sindex + 1, eline, eindex + 1)
+                ev.accept()
+                return
+            
+            super(MiniScintilla, self).keyPressEvent(ev)
+        else:
+            ev.ignore()
+    
     def focusInEvent(self, event):
         """
         Protected method called when the editor receives focus.
@@ -74,7 +101,8 @@
         assuming, that it is in the vicinity of the old position after the
         reread.
         
-        @param event the event object (QFocusEvent)
+        @param event the event object
+        @type QFocusEvent
         """
         self.mw.editorActGrp.setEnabled(True)
         try:
@@ -90,7 +118,8 @@
         """
         Protected method called when the editor loses focus.
         
-        @param event the event object (QFocusEvent)
+        @param event the event object
+        @type QFocusEvent
         """
         self.mw.editorActGrp.setEnabled(False)
         self.setCaretWidth(0)

eric ide

mercurial