--- a/src/eric7/QScintilla/TypingCompleters/CompleterYaml.py Sat Sep 09 17:20:31 2023 +0200 +++ b/src/eric7/QScintilla/TypingCompleters/CompleterYaml.py Sun Sep 10 18:04:28 2023 +0200 @@ -4,7 +4,7 @@ # """ -Module implementing a typing completer for Python. +Module implementing a typing completer for YAML. """ import re @@ -18,7 +18,7 @@ class CompleterYaml(CompleterBase): """ - Class implementing typing completer for Python. + Class implementing typing completer for YAML. """ def __init__(self, editor, parent=None): @@ -32,6 +32,9 @@ """ super().__init__(editor, parent) + self.__autoIndentationRe = re.compile(r"(?:\||\|-|\|\+|>|>-|>\+|-|:)(\s*)\r?\n") + self.__trailingBlankRe = re.compile(r"(?:[-:,?])(\s*)\r?\n") + self.readSettings() def readSettings(self): @@ -121,26 +124,45 @@ self.editor.insert("'") # new line - # indent after line ending with ':' elif char == "\n" and self.__autoIndentation: txt = self.editor.text(line - 1) - match = re.search( - r"(?:\||\|-|\|\+|>|>-|>\+|-|:)(\s*)\r?\n", - # __IGNORE_WARNING_W605__ - txt, - ) - if match is not None: - startBlanks = match.start(1) - endBlanks = match.end(1) - if startBlanks != -1 and startBlanks != endBlanks: - # previous line ends with whitespace, e.g. caused by - # blank insertion above - self.editor.setSelection(line - 1, startBlanks, line - 1, endBlanks) - self.editor.removeSelectedText() + if self.__autoIndentation and self.__autoIndentationRe.search(txt): + # indent after line ending with auto indentation character + match = self.__autoIndentationRe.search(txt) + if match is not None: + startBlanks = match.start(1) + endBlanks = match.end(1) + if startBlanks != -1 and startBlanks != endBlanks: + # previous line ends with whitespace, e.g. caused by + # blank insertion above + self.editor.setSelection( + line - 1, startBlanks, line - 1, endBlanks + ) + self.editor.removeSelectedText() + + self.editor.indent(line) + self.editor.setCursorPosition(line, 0) + self.editor.editorCommand(QsciScintilla.SCI_VCHOME) - self.editor.indent(line) - self.editor.setCursorPosition(line, 0) - self.editor.editorCommand(QsciScintilla.SCI_VCHOME) + elif ( + self.__insertBlankColon + or self.__insertBlankComma + or self.__insertBlankDash + or self.__insertBlankQuestion + ) and self.__trailingBlankRe.search(txt): + # remove blank at end of line inserted by blank insertion above + match = self.__trailingBlankRe.search(txt) + if match is not None: + startBlanks = match.start(1) + endBlanks = match.end(1) + if startBlanks != -1 and startBlanks != endBlanks: + self.editor.setSelection( + line - 1, startBlanks, line - 1, endBlanks + ) + self.editor.removeSelectedText() + + self.editor.setCursorPosition(line, 0) + self.editor.editorCommand(QsciScintilla.SCI_VCHOME) def __inComment(self, line, col): """