Editor, Mini Editor

Tue, 12 Jan 2021 17:19:02 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 12 Jan 2021 17:19:02 +0100
changeset 7969
62eff8b34a8d
parent 7967
f5da85158db2
child 7970
c4ee8a81584c

Editor, Mini Editor
- added code to enclose the current selection by entering ", ' or a bracket ( (, ), [, ], {, }, <, > ) characters

docs/changelog file | annotate | diff | comparison | revisions
eric6/APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.QScintilla.Editor.html file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.QScintilla.MiniEditor.html 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	Mon Jan 11 19:31:21 2021 +0100
+++ b/docs/changelog	Tue Jan 12 17:19:02 2021 +0100
@@ -19,7 +19,8 @@
      current cursor line (if it is greater than the current line) or until
      returning from the current frame
 - Editor
-  -- added code to enclose the current selection by entering " or ' characters
+  -- added code to enclose the current selection by entering ", ' or a bracket
+     ( (, ), [, ], {, }, <, > ) characters
   -- extended the exporters to support sub-styles
 - User Interface
   -- added capability to show Qt6 documentation (configurable)
--- a/eric6/APIs/Python3/eric6.api	Mon Jan 11 19:31:21 2021 +0100
+++ b/eric6/APIs/Python3/eric6.api	Tue Jan 12 17:19:02 2021 +0100
@@ -7342,6 +7342,7 @@
 eric6.QScintilla.Editor.Editor.ClassID?7
 eric6.QScintilla.Editor.Editor.ClassPrivateID?7
 eric6.QScintilla.Editor.Editor.ClassProtectedID?7
+eric6.QScintilla.Editor.Editor.EncloseChars?7
 eric6.QScintilla.Editor.Editor.EndEditToken?7
 eric6.QScintilla.Editor.Editor.EnumID?7
 eric6.QScintilla.Editor.Editor.FromDocumentID?7
@@ -7413,6 +7414,7 @@
 eric6.QScintilla.Editor.Editor.editorCommand?4(cmd)
 eric6.QScintilla.Editor.Editor.editorRenamed?7
 eric6.QScintilla.Editor.Editor.editorSaved?7
+eric6.QScintilla.Editor.Editor.encloseSelectedText?4()
 eric6.QScintilla.Editor.Editor.encodingChanged?7
 eric6.QScintilla.Editor.Editor.ensureVisible?4(line, expand=False)
 eric6.QScintilla.Editor.Editor.ensureVisibleTop?4(line, expand=False)
@@ -8154,6 +8156,8 @@
 eric6.QScintilla.MiniEditor.MiniEditor.showSearchWidget?4()
 eric6.QScintilla.MiniEditor.MiniEditor.textForFind?4()
 eric6.QScintilla.MiniEditor.MiniEditor?1(filename="", filetype="", parent=None, name=None)
+eric6.QScintilla.MiniEditor.MiniScintilla.EncloseChars?7
+eric6.QScintilla.MiniEditor.MiniScintilla.encloseSelectedText?4()
 eric6.QScintilla.MiniEditor.MiniScintilla.focusInEvent?4(event)
 eric6.QScintilla.MiniEditor.MiniScintilla.focusOutEvent?4(event)
 eric6.QScintilla.MiniEditor.MiniScintilla.getFileName?4()
Binary file eric6/Documentation/Help/source.qch has changed
--- a/eric6/Documentation/Help/source.qhp	Mon Jan 11 19:31:21 2021 +0100
+++ b/eric6/Documentation/Help/source.qhp	Tue Jan 12 17:19:02 2021 +0100
@@ -4991,6 +4991,7 @@
       <keyword name="Editor.dragMoveEvent" id="Editor.dragMoveEvent" ref="eric6.QScintilla.Editor.html#Editor.dragMoveEvent" />
       <keyword name="Editor.dropEvent" id="Editor.dropEvent" ref="eric6.QScintilla.Editor.html#Editor.dropEvent" />
       <keyword name="Editor.editorCommand" id="Editor.editorCommand" ref="eric6.QScintilla.Editor.html#Editor.editorCommand" />
+      <keyword name="Editor.encloseSelectedText" id="Editor.encloseSelectedText" ref="eric6.QScintilla.Editor.html#Editor.encloseSelectedText" />
       <keyword name="Editor.ensureVisible" id="Editor.ensureVisible" ref="eric6.QScintilla.Editor.html#Editor.ensureVisible" />
       <keyword name="Editor.ensureVisibleTop" id="Editor.ensureVisibleTop" ref="eric6.QScintilla.Editor.html#Editor.ensureVisibleTop" />
       <keyword name="Editor.event" id="Editor.event" ref="eric6.QScintilla.Editor.html#Editor.event" />
@@ -10039,6 +10040,7 @@
       <keyword name="MiniEditor.textForFind" id="MiniEditor.textForFind" ref="eric6.QScintilla.MiniEditor.html#MiniEditor.textForFind" />
       <keyword name="MiniScintilla" id="MiniScintilla" ref="eric6.QScintilla.MiniEditor.html#MiniScintilla" />
       <keyword name="MiniScintilla (Constructor)" id="MiniScintilla (Constructor)" ref="eric6.QScintilla.MiniEditor.html#MiniScintilla.__init__" />
+      <keyword name="MiniScintilla.encloseSelectedText" id="MiniScintilla.encloseSelectedText" ref="eric6.QScintilla.MiniEditor.html#MiniScintilla.encloseSelectedText" />
       <keyword name="MiniScintilla.focusInEvent" id="MiniScintilla.focusInEvent" ref="eric6.QScintilla.MiniEditor.html#MiniScintilla.focusInEvent" />
       <keyword name="MiniScintilla.focusOutEvent" id="MiniScintilla.focusOutEvent" ref="eric6.QScintilla.MiniEditor.html#MiniScintilla.focusOutEvent" />
       <keyword name="MiniScintilla.getFileName" id="MiniScintilla.getFileName" ref="eric6.QScintilla.MiniEditor.html#MiniScintilla.getFileName" />
--- a/eric6/Documentation/Source/eric6.QScintilla.Editor.html	Mon Jan 11 19:31:21 2021 +0100
+++ b/eric6/Documentation/Source/eric6.QScintilla.Editor.html	Tue Jan 12 17:19:02 2021 +0100
@@ -181,7 +181,7 @@
 <h3>Class Attributes</h3>
 
 <table>
-<tr><td>AttributeID</td></tr><tr><td>AttributePrivateID</td></tr><tr><td>AttributeProtectedID</td></tr><tr><td>CancelEditToken</td></tr><tr><td>ClassID</td></tr><tr><td>ClassPrivateID</td></tr><tr><td>ClassProtectedID</td></tr><tr><td>EndEditToken</td></tr><tr><td>EnumID</td></tr><tr><td>FromDocumentID</td></tr><tr><td>KeywordsID</td></tr><tr><td>MethodID</td></tr><tr><td>MethodPrivateID</td></tr><tr><td>MethodProtectedID</td></tr><tr><td>ModuleID</td></tr><tr><td>RequestSyncToken</td></tr><tr><td>Separator</td></tr><tr><td>StartEditToken</td></tr><tr><td>SyncToken</td></tr><tr><td>TemplateImageID</td></tr><tr><td>VcsConflictMarkerLineRegExpList</td></tr><tr><td>WarningCode</td></tr><tr><td>WarningStyle</td></tr>
+<tr><td>AttributeID</td></tr><tr><td>AttributePrivateID</td></tr><tr><td>AttributeProtectedID</td></tr><tr><td>CancelEditToken</td></tr><tr><td>ClassID</td></tr><tr><td>ClassPrivateID</td></tr><tr><td>ClassProtectedID</td></tr><tr><td>EncloseChars</td></tr><tr><td>EndEditToken</td></tr><tr><td>EnumID</td></tr><tr><td>FromDocumentID</td></tr><tr><td>KeywordsID</td></tr><tr><td>MethodID</td></tr><tr><td>MethodPrivateID</td></tr><tr><td>MethodProtectedID</td></tr><tr><td>ModuleID</td></tr><tr><td>RequestSyncToken</td></tr><tr><td>Separator</td></tr><tr><td>StartEditToken</td></tr><tr><td>SyncToken</td></tr><tr><td>TemplateImageID</td></tr><tr><td>VcsConflictMarkerLineRegExpList</td></tr><tr><td>WarningCode</td></tr><tr><td>WarningStyle</td></tr>
 </table>
 <h3>Class Methods</h3>
 
@@ -1073,6 +1073,10 @@
 <td>Public method to perform a simple editor command.</td>
 </tr>
 <tr>
+<td><a href="#Editor.encloseSelectedText">encloseSelectedText</a></td>
+<td>Local function to enclose the current selection with some characters.</td>
+</tr>
+<tr>
 <td><a href="#Editor.ensureVisible">ensureVisible</a></td>
 <td>Public slot to ensure, that the specified line is visible.</td>
 </tr>
@@ -4449,6 +4453,22 @@
 the scintilla command to be performed
 </dd>
 </dl>
+<a NAME="Editor.encloseSelectedText" ID="Editor.encloseSelectedText"></a>
+<h4>Editor.encloseSelectedText</h4>
+<b>encloseSelectedText</b>(<i></i>)
+
+<p>
+            Local function to enclose the current selection with some
+            characters.
+</p>
+<dl>
+
+<dt><i>encString</i> (str)</dt>
+<dd>
+string to use to enclose the selection
+                (one or two characters)
+</dd>
+</dl>
 <a NAME="Editor.ensureVisible" ID="Editor.ensureVisible"></a>
 <h4>Editor.ensureVisible</h4>
 <b>ensureVisible</b>(<i>line, expand=False</i>)
--- a/eric6/Documentation/Source/eric6.QScintilla.MiniEditor.html	Mon Jan 11 19:31:21 2021 +0100
+++ b/eric6/Documentation/Source/eric6.QScintilla.MiniEditor.html	Tue Jan 12 17:19:02 2021 +0100
@@ -1589,7 +1589,7 @@
 <h3>Class Attributes</h3>
 
 <table>
-<tr><td>None</td></tr>
+<tr><td>EncloseChars</td></tr>
 </table>
 <h3>Class Methods</h3>
 
@@ -1605,6 +1605,10 @@
 <td>Constructor</td>
 </tr>
 <tr>
+<td><a href="#MiniScintilla.encloseSelectedText">encloseSelectedText</a></td>
+<td>Local function to enclose the current selection with some characters.</td>
+</tr>
+<tr>
 <td><a href="#MiniScintilla.focusInEvent">focusInEvent</a></td>
 <td>Protected method called when the editor receives focus.</td>
 </tr>
@@ -1645,6 +1649,22 @@
 parent widget
 </dd>
 </dl>
+<a NAME="MiniScintilla.encloseSelectedText" ID="MiniScintilla.encloseSelectedText"></a>
+<h4>MiniScintilla.encloseSelectedText</h4>
+<b>encloseSelectedText</b>(<i></i>)
+
+<p>
+            Local function to enclose the current selection with some
+            characters.
+</p>
+<dl>
+
+<dt><i>encString</i> (str)</dt>
+<dd>
+string to use to enclose the selection
+                (one or two characters)
+</dd>
+</dl>
 <a NAME="MiniScintilla.focusInEvent" ID="MiniScintilla.focusInEvent"></a>
 <h4>MiniScintilla.focusInEvent</h4>
 <b>focusInEvent</b>(<i>event</i>)
--- a/eric6/QScintilla/Editor.py	Mon Jan 11 19:31:21 2021 +0100
+++ b/eric6/QScintilla/Editor.py	Tue Jan 12 17:19:02 2021 +0100
@@ -157,6 +157,19 @@
         r"""^>>>>>>> .*?$""",
     )
     
+    EncloseChars = {
+        '"': '"',
+        "'": "'",
+        "(": "()",
+        ")": "()",
+        "{": "{}",          # __IGNORE_WARNING_M613__
+        "}": "{}",          # __IGNORE_WARNING_M613__
+        "[": "[]",
+        "]": "[]",
+        "<": "<>",
+        ">": "<>",
+    }
+    
     def __init__(self, dbs, fn="", vm=None,
                  filetype="", editor=None, tv=None):
         """
@@ -6938,19 +6951,37 @@
         @param ev key event
         @type QKeyEvent
         """
+        def encloseSelectedText(encString):
+            """
+            Local function to enclose the current selection with some
+            characters.
+            
+            @param encString string to use to enclose the selection
+                (one or two characters)
+            @type str
+            """
+            startChar = encString[0]
+            if len(encString) == 2:
+                endChar = encString[1]
+            else:
+                endChar = startChar
+            
+            sline, sindex, eline, eindex = self.getSelection()
+            replaceText = startChar + self.selectedText() + endChar
+            self.beginUndoAction()
+            self.replaceSelectedText(replaceText)
+            self.endUndoAction()
+            self.setSelection(sline, sindex + 1, eline, eindex + 1)
+        
         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
+            if self.hasSelectedText():
+                if txt in Editor.EncloseChars:
+                    encloseSelectedText(Editor.EncloseChars[txt])
+                    ev.accept()
+                    return
             
             super(Editor, self).keyPressEvent(ev)
         else:
--- a/eric6/QScintilla/MiniEditor.py	Mon Jan 11 19:31:21 2021 +0100
+++ b/eric6/QScintilla/MiniEditor.py	Tue Jan 12 17:19:02 2021 +0100
@@ -47,6 +47,19 @@
     Class implementing a QsciScintillaCompat subclass for handling focus
     events.
     """
+    EncloseChars = {
+        '"': '"',
+        "'": "'",
+        "(": "()",
+        ")": "()",
+        "{": "{}",          # __IGNORE_WARNING_M613__
+        "}": "{}",          # __IGNORE_WARNING_M613__
+        "[": "[]",
+        "]": "[]",
+        "<": "<>",
+        ">": "<>",
+    }
+    
     def __init__(self, parent=None):
         """
         Constructor
@@ -74,19 +87,37 @@
         @param ev key event
         @type QKeyEvent
         """
+        def encloseSelectedText(encString):
+            """
+            Local function to enclose the current selection with some
+            characters.
+            
+            @param encString string to use to enclose the selection
+                (one or two characters)
+            @type str
+            """
+            startChar = encString[0]
+            if len(encString) == 2:
+                endChar = encString[1]
+            else:
+                endChar = startChar
+            
+            sline, sindex, eline, eindex = self.getSelection()
+            replaceText = startChar + self.selectedText() + endChar
+            self.beginUndoAction()
+            self.replaceSelectedText(replaceText)
+            self.endUndoAction()
+            self.setSelection(sline, sindex + 1, eline, eindex + 1)
+        
         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
+            if self.hasSelectedText():
+                if txt in MiniScintilla.EncloseChars:
+                    encloseSelectedText(MiniScintilla.EncloseChars[txt])
+                    ev.accept()
+                    return
             
             super(MiniScintilla, self).keyPressEvent(ev)
         else:

eric ide

mercurial