eric6/QScintilla/MiniEditor.py

branch
multi_processing
changeset 7864
431e6816c60c
parent 7836
2f0d208b8137
child 7900
72b88fb20261
--- a/eric6/QScintilla/MiniEditor.py	Sun Dec 06 17:53:05 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