diff -r 0572a215bd2f -r 5994b80b8760 eric6/QScintilla/TypingCompleters/CompleterPython.py --- a/eric6/QScintilla/TypingCompleters/CompleterPython.py Sun Apr 11 16:53:48 2021 +0200 +++ b/eric6/QScintilla/TypingCompleters/CompleterPython.py Sun Apr 11 18:45:10 2021 +0200 @@ -143,10 +143,9 @@ # skip matching closing parenthesis elif char in [')', '}', ']']: txt = self.editor.text(line) - if col < len(txt) and char == txt[col]: - if self.__skipBrace: - self.editor.setSelection(line, col, line, col + 1) - self.editor.removeSelectedText() + if col < len(txt) and char == txt[col] and self.__skipBrace: + self.editor.setSelection(line, col, line, col + 1) + self.editor.removeSelectedText() # space # insert import, dedent to if for elif, dedent to try for except, @@ -171,34 +170,29 @@ # comma # insert blank - elif char == ',': - if self.__insertBlank: - self.editor.insert(' ') - self.editor.setCursorPosition(line, col + 1) + elif char == ',' and self.__insertBlank: + self.editor.insert(' ') + self.editor.setCursorPosition(line, col + 1) # open curly brace # insert closing brace - elif char == '{': - if self.__insertClosingBrace: - self.editor.insert('}') + elif char == '{' and self.__insertClosingBrace: + self.editor.insert('}') # open bracket # insert closing bracket - elif char == '[': - if self.__insertClosingBrace: - self.editor.insert(']') + elif char == '[' and self.__insertClosingBrace: + self.editor.insert(']') # double quote # insert double quote - elif char == '"': - if self.__insertQuote: - self.editor.insert('"') + elif char == '"' and self.__insertQuote: + self.editor.insert('"') # quote # insert quote - elif char == '\'': - if self.__insertQuote: - self.editor.insert('\'') + elif char == '\'' and self.__insertQuote: + self.editor.insert('\'') # colon # skip colon, dedent to if for else: @@ -219,37 +213,36 @@ # new line # indent to opening brace - elif char == '\n': - if self.__indentBrace: - txt = self.editor.text(line - 1) - if re.search(":\r?\n", txt) is None: - self.editor.beginUndoAction() - stxt = txt.strip() - if stxt and stxt[-1] in ("(", "[", "{"): - # indent one more level - self.editor.indent(line) - self.editor.editorCommand(QsciScintilla.SCI_VCHOME) - else: - # indent to the level of the opening brace - openCount = len(re.findall("[({[]", txt)) - closeCount = len(re.findall(r"[)}\]]", txt)) - if openCount > closeCount: - openCount = 0 - closeCount = 0 - openList = list(re.finditer("[({[]", txt)) - index = len(openList) - 1 - while index > -1 and openCount == closeCount: - lastOpenIndex = openList[index].start() - txt2 = txt[lastOpenIndex:] - openCount = len(re.findall("[({[]", txt2)) - closeCount = len(re.findall(r"[)}\]]", txt2)) - index -= 1 - if openCount > closeCount and lastOpenIndex > col: - self.editor.insert( - ' ' * (lastOpenIndex - col + 1)) - self.editor.setCursorPosition( - line, lastOpenIndex + 1) - self.editor.endUndoAction() + elif char == '\n' and self.__indentBrace: + txt = self.editor.text(line - 1) + if re.search(":\r?\n", txt) is None: + self.editor.beginUndoAction() + stxt = txt.strip() + if stxt and stxt[-1] in ("(", "[", "{"): + # indent one more level + self.editor.indent(line) + self.editor.editorCommand(QsciScintilla.SCI_VCHOME) + else: + # indent to the level of the opening brace + openCount = len(re.findall("[({[]", txt)) + closeCount = len(re.findall(r"[)}\]]", txt)) + if openCount > closeCount: + openCount = 0 + closeCount = 0 + openList = list(re.finditer("[({[]", txt)) + index = len(openList) - 1 + while index > -1 and openCount == closeCount: + lastOpenIndex = openList[index].start() + txt2 = txt[lastOpenIndex:] + openCount = len(re.findall("[({[]", txt2)) + closeCount = len(re.findall(r"[)}\]]", txt2)) + index -= 1 + if openCount > closeCount and lastOpenIndex > col: + self.editor.insert( + ' ' * (lastOpenIndex - col + 1)) + self.editor.setCursorPosition( + line, lastOpenIndex + 1) + self.editor.endUndoAction() def __dedentToIf(self): """