--- a/eric6/QScintilla/MiniEditor.py Sun Jan 17 13:53:08 2021 +0100 +++ b/eric6/QScintilla/MiniEditor.py Mon Feb 01 10:38:16 2021 +0100 @@ -47,11 +47,25 @@ Class implementing a QsciScintillaCompat subclass for handling focus events. """ + EncloseChars = { + '"': '"', + "'": "'", + "(": "()", + ")": "()", + "{": "{}", # __IGNORE_WARNING_M613__ + "}": "{}", # __IGNORE_WARNING_M613__ + "[": "[]", + "]": "[]", + "<": "<>", + ">": "<>", + } + def __init__(self, parent=None): """ Constructor - @param parent parent widget (QWidget) + @param parent parent widget + @type QWidget """ super(MiniScintilla, self).__init__(parent) @@ -61,10 +75,54 @@ """ 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 + """ + 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 self.hasSelectedText(): + if txt in MiniScintilla.EncloseChars: + encloseSelectedText(MiniScintilla.EncloseChars[txt]) + 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 +132,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 +149,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) @@ -336,9 +396,9 @@ """ E5MessageBox.about( self, - self.tr("About eric6 Mini Editor"), + self.tr("About eric Mini Editor"), self.tr( - "The eric6 Mini Editor is an editor component" + "The eric Mini Editor is an editor component" " based on QScintilla. It may be used for simple" " editing tasks, that don't need the power of" " a full blown editor.")) @@ -347,7 +407,7 @@ """ Private slot to handle the About Qt dialog. """ - E5MessageBox.aboutQt(self, "eric6 Mini Editor") + E5MessageBox.aboutQt(self, "eric Mini Editor") def __whatsThis(self): """ @@ -466,7 +526,7 @@ self.__createViewActions() # read the keyboard shortcuts and make them identical to the main - # eric6 shortcuts + # eric shortcuts for act in self.helpActions: self.__readShortcut(act, "General") for act in self.editActions: @@ -2506,7 +2566,7 @@ if self.__textEdit.isModified(): ret = E5MessageBox.okToClearData( self, - self.tr("eric6 Mini Editor"), + self.tr("eric Mini Editor"), self.tr("The document has unsaved changes."), self.__save) return ret @@ -3184,7 +3244,7 @@ language (string) @param initTextDisplay flag indicating an initialization of the text display is required as well (boolean) - @keyparam pyname name of the pygments lexer to use (string) + @param pyname name of the pygments lexer to use (string) """ self.__bindLexer(filename, pyname=pyname) self.__textEdit.recolor() @@ -3253,7 +3313,7 @@ @param filename filename used to determine the associated lexer language (string) - @keyparam pyname name of the pygments lexer to use (string) + @param pyname name of the pygments lexer to use (string) """ if ( self.lexer_ is not None and @@ -3592,7 +3652,7 @@ @param line line number to go to @type int - @keyparam pos position in line to go to + @param pos position in line to go to @type int """ self.__textEdit.setCursorPosition(line - 1, pos - 1)