ProjectKivy/CompleterKivy.py

branch
eric7
changeset 64
c3b1bb6fddd6
parent 59
fb361b396c68
child 68
20cdd6e03807
diff -r a476f5593d8b -r c3b1bb6fddd6 ProjectKivy/CompleterKivy.py
--- a/ProjectKivy/CompleterKivy.py	Sun Sep 10 20:02:16 2023 +0200
+++ b/ProjectKivy/CompleterKivy.py	Mon Sep 11 13:39:19 2023 +0200
@@ -35,6 +35,8 @@
         self.__plugin = plugin
 
         self.__autoIndentationRe = re.compile(r"(?:\(|\[|{|:)(\s*)\r?\n")
+        self.__trailingBlankRe = re.compile(r"(?:,)(\s*)\r?\n")
+        # Trailing blank after ':' is already covered by auto indent rule
 
         self.readSettings()
 
@@ -141,22 +143,42 @@
             self.editor.insert("'")
 
         # new line
-        # indent after line ending with ':'
-        elif char == "\n" and self.__autoIndentation:
+        # indent after line ending with auto indentation character
+        elif char == "\n":
             txt = self.editor.text(line - 1)
-            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()
+            if self.__autoIndentation and self.__autoIndentationRe.search(txt):
+                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
+            ) 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):
         """

eric ide

mercurial