eric6/QScintilla/TypingCompleters/CompleterYaml.py

changeset 8222
5994b80b8760
parent 8218
7c09585bd960
child 8228
772103b14c18
equal deleted inserted replaced
8221:0572a215bd2f 8222:5994b80b8760
75 if self.__inComment(line, col): 75 if self.__inComment(line, col):
76 return 76 return
77 77
78 # open curly brace 78 # open curly brace
79 # insert closing brace 79 # insert closing brace
80 if char == '{': 80 if char == '{' and self.__insertClosingBrace:
81 if self.__insertClosingBrace: 81 self.editor.insert('}')
82 self.editor.insert('}')
83 82
84 # open bracket 83 # open bracket
85 # insert closing bracket 84 # insert closing bracket
86 elif char == '[': 85 elif char == '[' and self.__insertClosingBrace:
87 if self.__insertClosingBrace: 86 self.editor.insert(']')
88 self.editor.insert(']')
89 87
90 # closing parenthesis 88 # closing parenthesis
91 # skip matching closing parenthesis 89 # skip matching closing parenthesis
92 elif char in ['}', ']']: 90 elif char in ['}', ']']:
93 txt = self.editor.text(line) 91 txt = self.editor.text(line)
94 if col < len(txt) and char == txt[col]: 92 if col < len(txt) and char == txt[col] and self.__skipBrace:
95 if self.__skipBrace: 93 self.editor.setSelection(line, col, line, col + 1)
96 self.editor.setSelection(line, col, line, col + 1) 94 self.editor.removeSelectedText()
97 self.editor.removeSelectedText()
98 95
99 # dash 96 # dash
100 # insert blank 97 # insert blank
101 elif char == '-': 98 elif char == '-' and self.__insertBlankDash:
102 if self.__insertBlankDash: 99 self.editor.insert(' ')
103 self.editor.insert(' ') 100 self.editor.setCursorPosition(line, col + 1)
104 self.editor.setCursorPosition(line, col + 1)
105 101
106 # colon 102 # colon
107 # 1. skip colon if not last character 103 # 1. skip colon if not last character
108 # 2. insert blank if last character 104 # 2. insert blank if last character
109 elif char == ':': 105 elif char == ':':
110 text = self.editor.text(line) 106 text = self.editor.text(line)
111 if col < len(text) and char == text[col]: 107 if col < len(text) and char == text[col]:
112 if self.__colonDetection: 108 if self.__colonDetection:
113 self.editor.setSelection(line, col, line, col + 1) 109 self.editor.setSelection(line, col, line, col + 1)
114 self.editor.removeSelectedText() 110 self.editor.removeSelectedText()
115 elif self.__insertBlankColon: 111 elif self.__insertBlankColon and col == len(text.rstrip()):
116 if col == len(text.rstrip()): 112 self.editor.insert(' ')
117 self.editor.insert(' ') 113 self.editor.setCursorPosition(line, col + 1)
118 self.editor.setCursorPosition(line, col + 1)
119 114
120 # question mark 115 # question mark
121 # insert blank 116 # insert blank
122 elif char == '?': 117 elif char == '?' and self.__insertBlankQuestion:
123 if self.__insertBlankQuestion: 118 self.editor.insert(' ')
124 self.editor.insert(' ') 119 self.editor.setCursorPosition(line, col + 1)
125 self.editor.setCursorPosition(line, col + 1)
126 120
127 # comma 121 # comma
128 # insert blank 122 # insert blank
129 elif char == ',': 123 elif char == ',' and self.__insertBlankComma:
130 if self.__insertBlankComma: 124 self.editor.insert(' ')
131 self.editor.insert(' ') 125 self.editor.setCursorPosition(line, col + 1)
132 self.editor.setCursorPosition(line, col + 1)
133 126
134 # double quote 127 # double quote
135 # insert double quote 128 # insert double quote
136 elif char == '"': 129 elif char == '"' and self.__insertQuote:
137 if self.__insertQuote: 130 self.editor.insert('"')
138 self.editor.insert('"')
139 131
140 # quote 132 # quote
141 # insert quote 133 # insert quote
142 elif char == "'": 134 elif char == "'" and self.__insertQuote:
143 if self.__insertQuote: 135 self.editor.insert("'")
144 self.editor.insert("'")
145 136
146 # new line 137 # new line
147 # indent after line ending with ':' 138 # indent after line ending with ':'
148 elif char == '\n': 139 elif char == '\n' and self.__autoIndentation:
149 if self.__autoIndentation: 140 txt = self.editor.text(line - 1)
150 txt = self.editor.text(line - 1) 141 match = re.search(
151 match = re.search( 142 "(?:\||\|-|\|\+|>|>-|>\+|-|:)(\s*)\r?\n",
152 "(?:\||\|-|\|\+|>|>-|>\+|-|:)(\s*)\r?\n", 143 # __IGNORE_WARNING_W605__
153 # __IGNORE_WARNING_W605__ 144 txt)
154 txt) 145 if match is not None:
155 if match is not None: 146 startBlanks = match.start(1)
156 startBlanks = match.start(1) 147 endBlanks = match.end(1)
157 endBlanks = match.end(1) 148 if startBlanks != -1 and startBlanks != endBlanks:
158 if startBlanks != -1 and startBlanks != endBlanks: 149 # previous line ends with whitespace, e.g. caused by
159 # previous line ends with whitespace, e.g. caused by 150 # blank insertion above
160 # blank insertion above 151 self.editor.setSelection(line - 1, startBlanks,
161 self.editor.setSelection(line - 1, startBlanks, 152 line - 1, endBlanks)
162 line - 1, endBlanks) 153 self.editor.removeSelectedText()
163 self.editor.removeSelectedText() 154
164 155 self.editor.indent(line)
165 self.editor.indent(line) 156 self.editor.setCursorPosition(line, 0)
166 self.editor.setCursorPosition(line, 0) 157 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
167 self.editor.editorCommand(QsciScintilla.SCI_VCHOME)
168 158
169 def __inComment(self, line, col): 159 def __inComment(self, line, col):
170 """ 160 """
171 Private method to check, if the cursor is inside a comment. 161 Private method to check, if the cursor is inside a comment.
172 162

eric ide

mercurial