src/eric7/QScintilla/TypingCompleters/CompleterYaml.py

branch
eric7
changeset 10201
5beaa25bdfbe
parent 10162
e7040c88b39e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10200:7c282bf19646 10201:5beaa25bdfbe
2 2
3 # Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a typing completer for Python. 7 Module implementing a typing completer for YAML.
8 """ 8 """
9 9
10 import re 10 import re
11 11
12 from PyQt6.Qsci import QsciScintilla 12 from PyQt6.Qsci import QsciScintilla
16 from .CompleterBase import CompleterBase 16 from .CompleterBase import CompleterBase
17 17
18 18
19 class CompleterYaml(CompleterBase): 19 class CompleterYaml(CompleterBase):
20 """ 20 """
21 Class implementing typing completer for Python. 21 Class implementing typing completer for YAML.
22 """ 22 """
23 23
24 def __init__(self, editor, parent=None): 24 def __init__(self, editor, parent=None):
25 """ 25 """
26 Constructor 26 Constructor
29 @type QScintilla.Editor 29 @type QScintilla.Editor
30 @param parent reference to the parent object 30 @param parent reference to the parent object
31 @type QObject 31 @type QObject
32 """ 32 """
33 super().__init__(editor, parent) 33 super().__init__(editor, parent)
34
35 self.__autoIndentationRe = re.compile(r"(?:\||\|-|\|\+|>|>-|>\+|-|:)(\s*)\r?\n")
36 self.__trailingBlankRe = re.compile(r"(?:[-:,?])(\s*)\r?\n")
34 37
35 self.readSettings() 38 self.readSettings()
36 39
37 def readSettings(self): 40 def readSettings(self):
38 """ 41 """
119 # insert quote 122 # insert quote
120 elif char == "'" and self.__insertQuote: 123 elif char == "'" and self.__insertQuote:
121 self.editor.insert("'") 124 self.editor.insert("'")
122 125
123 # new line 126 # new line
124 # indent after line ending with ':'
125 elif char == "\n" and self.__autoIndentation: 127 elif char == "\n" and self.__autoIndentation:
126 txt = self.editor.text(line - 1) 128 txt = self.editor.text(line - 1)
127 match = re.search( 129 if self.__autoIndentation and self.__autoIndentationRe.search(txt):
128 r"(?:\||\|-|\|\+|>|>-|>\+|-|:)(\s*)\r?\n", 130 # indent after line ending with auto indentation character
129 # __IGNORE_WARNING_W605__ 131 match = self.__autoIndentationRe.search(txt)
130 txt, 132 if match is not None:
131 ) 133 startBlanks = match.start(1)
132 if match is not None: 134 endBlanks = match.end(1)
133 startBlanks = match.start(1) 135 if startBlanks != -1 and startBlanks != endBlanks:
134 endBlanks = match.end(1) 136 # previous line ends with whitespace, e.g. caused by
135 if startBlanks != -1 and startBlanks != endBlanks: 137 # blank insertion above
136 # previous line ends with whitespace, e.g. caused by 138 self.editor.setSelection(
137 # blank insertion above 139 line - 1, startBlanks, line - 1, endBlanks
138 self.editor.setSelection(line - 1, startBlanks, line - 1, endBlanks) 140 )
139 self.editor.removeSelectedText() 141 self.editor.removeSelectedText()
140 142
141 self.editor.indent(line) 143 self.editor.indent(line)
142 self.editor.setCursorPosition(line, 0) 144 self.editor.setCursorPosition(line, 0)
143 self.editor.editorCommand(QsciScintilla.SCI_VCHOME) 145 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
146
147 elif (
148 self.__insertBlankColon
149 or self.__insertBlankComma
150 or self.__insertBlankDash
151 or self.__insertBlankQuestion
152 ) and self.__trailingBlankRe.search(txt):
153 # remove blank at end of line inserted by blank insertion above
154 match = self.__trailingBlankRe.search(txt)
155 if match is not None:
156 startBlanks = match.start(1)
157 endBlanks = match.end(1)
158 if startBlanks != -1 and startBlanks != endBlanks:
159 self.editor.setSelection(
160 line - 1, startBlanks, line - 1, endBlanks
161 )
162 self.editor.removeSelectedText()
163
164 self.editor.setCursorPosition(line, 0)
165 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
144 166
145 def __inComment(self, line, col): 167 def __inComment(self, line, col):
146 """ 168 """
147 Private method to check, if the cursor is inside a comment. 169 Private method to check, if the cursor is inside a comment.
148 170

eric ide

mercurial