eric6/QScintilla/TypingCompleters/CompleterRuby.py

changeset 6997
24eabcea4c59
parent 6942
2602857055c5
child 7229
53054eb5b15a
--- a/eric6/QScintilla/TypingCompleters/CompleterRuby.py	Sat May 04 14:01:19 2019 +0200
+++ b/eric6/QScintilla/TypingCompleters/CompleterRuby.py	Sat May 04 14:34:51 2019 +0200
@@ -12,7 +12,7 @@
 import re
 
 from PyQt5.QtCore import QRegExp
-from PyQt5.Qsci import QsciLexerRuby
+from PyQt5.Qsci import QsciLexerRuby, QsciScintilla
 
 from .CompleterBase import CompleterBase
 
@@ -141,22 +141,30 @@
             elif self.__insertHereDoc and self.__hereRX.exactMatch(txt):
                 self.editor.insert(self.__hereRX.cap(1))
             elif self.__indentBrace and re.search(":\r?\n", txt) is None:
-                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)
+                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)
     
     def __inComment(self, line, col):
         """

eric ide

mercurial