diff -r e01ae92db699 -r 31965986ecd1 eric6/QScintilla/MiniEditor.py --- a/eric6/QScintilla/MiniEditor.py Sat Mar 06 10:00:52 2021 +0100 +++ b/eric6/QScintilla/MiniEditor.py Sun Mar 28 15:00:11 2021 +0200 @@ -80,6 +80,22 @@ """ 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 = ['()', '[]', '{}', '<>', "''", '""'] + # __IGNORE_WARNING_M613__ + 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. @@ -294,7 +310,8 @@ self.__cursorPositionChanged) self.__textEdit.linesChanged.connect(self.__resizeLinenoMargin) - self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu) + self.__textEdit.setContextMenuPolicy( + Qt.ContextMenuPolicy.CustomContextMenu) self.__textEdit.customContextMenuRequested.connect( self.__contextMenuRequested) @@ -764,7 +781,11 @@ #################################################################### self.esm = QSignalMapper(self) - self.esm.mapped[int].connect(self.__textEdit.editorCommand) + try: + self.esm.mappedInt.connect(self.__textEdit.editorCommand) + except AttributeError: + # pre Qt 5.15 + self.esm.mapped[int].connect(self.__textEdit.editorCommand) self.editorActGrp = createActionGroup(self) @@ -2853,7 +2874,7 @@ Preferences.getEditorColour("FoldMarkersForeground"), Preferences.getEditorColour("FoldMarkersBackground")) else: - self.__textEdit.setFolding(QsciScintilla.NoFoldStyle) + self.__textEdit.setFolding(QsciScintilla.FoldStyle.NoFoldStyle) def __resizeLinenoMargin(self): """ @@ -2893,7 +2914,8 @@ self.__textEdit.setIndentationGuidesForegroundColor( Preferences.getEditorColour("IndentationGuidesForeground")) if Preferences.getEditor("ShowWhitespace"): - self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsVisible) + self.__textEdit.setWhitespaceVisibility( + QsciScintilla.WhitespaceVisibility.WsVisible) self.__textEdit.setWhitespaceForegroundColor( Preferences.getEditorColour("WhitespaceForeground")) self.__textEdit.setWhitespaceBackgroundColor( @@ -2901,13 +2923,16 @@ self.__textEdit.setWhitespaceSize( Preferences.getEditor("WhitespaceSize")) else: - self.__textEdit.setWhitespaceVisibility(QsciScintilla.WsInvisible) + self.__textEdit.setWhitespaceVisibility( + QsciScintilla.WhitespaceVisibility.WsInvisible) self.__textEdit.setEolVisibility(Preferences.getEditor("ShowEOL")) self.__textEdit.setAutoIndent(Preferences.getEditor("AutoIndentation")) if Preferences.getEditor("BraceHighlighting"): - self.__textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) + self.__textEdit.setBraceMatching( + QsciScintilla.BraceMatch.SloppyBraceMatch) else: - self.__textEdit.setBraceMatching(QsciScintilla.NoBraceMatch) + self.__textEdit.setBraceMatching( + QsciScintilla.BraceMatch.NoBraceMatch) self.__textEdit.setMatchedBraceForegroundColor( Preferences.getEditorColour("MatchingBrace")) self.__textEdit.setMatchedBraceBackgroundColor( @@ -2921,7 +2946,7 @@ Preferences.getEditorColour("SelectionBackground")) else: self.__textEdit.setSelectionBackgroundColor( - QApplication.palette().color(QPalette.Highlight)) + QApplication.palette().color(QPalette.ColorRole.Highlight)) if Preferences.getEditor("ColourizeSelText"): self.__textEdit.resetSelectionForegroundColor() elif Preferences.getEditor("CustomSelectionColours"): @@ -2929,7 +2954,8 @@ Preferences.getEditorColour("SelectionForeground")) else: self.__textEdit.setSelectionForegroundColor( - QApplication.palette().color(QPalette.HighlightedText)) + QApplication.palette().color( + QPalette.ColorRole.HighlightedText)) self.__textEdit.setSelectionToEol( Preferences.getEditor("ExtendSelectionToEol")) self.__textEdit.setCaretForegroundColor( @@ -2976,6 +3002,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): """ @@ -3009,19 +3039,24 @@ Private slot to print the text. """ from .Printer import Printer - printer = Printer(mode=QPrinter.HighResolution) + printer = Printer(mode=QPrinter.PrinterMode.HighResolution) sb = self.statusBar() printDialog = QPrintDialog(printer, self) if self.__textEdit.hasSelectedText(): - printDialog.setOption(QAbstractPrintDialog.PrintSelection, True) - if printDialog.exec() == QDialog.Accepted: + printDialog.setOption( + QAbstractPrintDialog.PrintDialogOption.PrintSelection, + True) + if printDialog.exec() == QDialog.DialogCode.Accepted: sb.showMessage(self.tr('Printing...')) QApplication.processEvents() if self.__curFile: printer.setDocName(QFileInfo(self.__curFile).fileName()) else: printer.setDocName(self.tr("Untitled")) - if printDialog.printRange() == QAbstractPrintDialog.Selection: + if ( + printDialog.printRange() == + QAbstractPrintDialog.PrintRange.Selection + ): # get the selection fromLine, fromIndex, toLine, toIndex = ( self.__textEdit.getSelection() @@ -3048,7 +3083,7 @@ from PyQt5.QtPrintSupport import QPrintPreviewDialog from .Printer import Printer - printer = Printer(mode=QPrinter.HighResolution) + printer = Printer(mode=QPrinter.PrinterMode.HighResolution) if self.__curFile: printer.setDocName(QFileInfo(self.__curFile).fileName()) else: @@ -3364,7 +3399,10 @@ self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded) # get the font for style 0 and set it as the default font - key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) + if pyname and pyname.startswith("Pygments|"): + key = 'Scintilla/Guessed/style0/font' + else: + key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) fdesc = Preferences.Prefs.settings.value(key) if fdesc is not None: font = QFont(fdesc[0], int(fdesc[1])) @@ -3741,11 +3779,11 @@ if option == "EOLMode": value = config["end_of_line"] if value == "lf": - value = QsciScintilla.EolUnix + value = QsciScintilla.EolMode.EolUnix elif value == "crlf": - value = QsciScintilla.EolWindows + value = QsciScintilla.EolMode.EolWindows elif value == "cr": - value = QsciScintilla.EolMac + value = QsciScintilla.EolMode.EolMac else: value = None elif option == "DefaultEncoding": @@ -3850,7 +3888,7 @@ """ from QScintilla.ZoomDialog import ZoomDialog dlg = ZoomDialog(self.getZoom(), self, None, True) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: value = dlg.getZoomSize() self.__zoomTo(value)