Editor

Wed, 17 Mar 2021 19:54:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 17 Mar 2021 19:54:32 +0100
changeset 8165
61ca9619decb
parent 8164
c8b88e73b56f
child 8166
bd5cd5858503

Editor
- added capability to delete the matching brace if the cursor is in between them (e.g. {}) and backspace is pressed

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	Tue Mar 16 17:29:42 2021 +0100
+++ b/docs/changelog	Wed Mar 17 19:54:32 2021 +0100
@@ -5,6 +5,9 @@
 - Debugger
   -- extended the Start... dialogs to allow to override some global
      configuration settings (redirect stdin/stdout/stderr)
+- Editor
+  -- added capability to delete the matching brace if the cursor is
+     in between them (e.g. {}) and backspace is pressed
 - Pip Interface
   -- added support for a re-installation of selected packages
 - Shell
--- a/eric6/QScintilla/Editor.py	Tue Mar 16 17:29:42 2021 +0100
+++ b/eric6/QScintilla/Editor.py	Wed Mar 17 19:54:32 2021 +0100
@@ -4714,6 +4714,9 @@
         self.setVirtualSpaceOptions(
             Preferences.getEditor("VirtualSpaceOptions"))
         
+        # to avoid errors due to line endings by pasting
+        self.SendScintilla(QsciScintilla.SCI_SETPASTECONVERTENDINGS, True)
+        
         self.__markerMap.setEnabled(True)
     
     def __setEolMode(self):
@@ -7723,6 +7726,13 @@
                                  for t in templateNames])
                             return
         
+        elif cmd == QsciScintilla.SCI_DELETEBACK:
+            line, index = self.getCursorPosition()
+            text = self.text(line)[index - 1:index + 1]
+            matchingPairs = ['()', '[]', '{}', '<>', "''", '""']
+            if text in matchingPairs:
+                self.delete()
+        
         super(Editor, self).editorCommand(cmd)
     
     def __applyTemplate(self, templateName, language):
--- a/eric6/QScintilla/MiniEditor.py	Tue Mar 16 17:29:42 2021 +0100
+++ b/eric6/QScintilla/MiniEditor.py	Wed Mar 17 19:54:32 2021 +0100
@@ -80,6 +80,21 @@
         """
         return self.mw.getFileName()
     
+    def editorCommand(self, cmd):
+        """
+        Public method to perform a simple editor command.
+        
+        @param cmd the scintilla command to be performed (integer)
+        """
+        if cmd == QsciScintilla.SCI_DELETEBACK:
+            line, index = self.getCursorPosition()
+            text = self.text(line)[index - 1:index + 1]
+            matchingPairs = ['()', '[]', '{}', '<>', "''", '""']
+            if text in matchingPairs:
+                self.delete()
+        
+        super(MiniScintilla, self).editorCommand(cmd)
+    
     def keyPressEvent(self, ev):
         """
         Protected method to handle the user input a key at a time.
@@ -2986,6 +3001,10 @@
         
         self.__textEdit.setVirtualSpaceOptions(
             Preferences.getEditor("VirtualSpaceOptions"))
+        
+        # to avoid errors due to line endings by pasting
+        self.__textEdit.SendScintilla(
+            QsciScintilla.SCI_SETPASTECONVERTENDINGS, True)
     
     def __setEolMode(self):
         """

eric ide

mercurial