| | 154 | # When we insert a new line, the colorization isn't always |
| | 155 | # immediately updated, so we have to force that here before |
| | 156 | # calling findIndent |
| | 157 | stc.ReplaceTarget(linesep) |
| | 158 | pos += len(linesep) |
| | 159 | end = min(pos + 1, stc.GetTextLength()) |
| | 160 | # Colorize the entire last line up to one character beyond the |
| | 161 | # newly inserted linesep character, guaranteeing that the new line |
| | 162 | # will have the correct fold property set. |
| | 163 | stc.Colourise(stc.PositionFromLine(linenum), end) |
| | 164 | stc.SetTargetStart(pos) |
| | 165 | stc.SetTargetEnd(pos) |
| | 178 | |
| | 179 | def electricChar(self, stc, uchar): |
| | 180 | """Autoindent in response to a special character |
| | 181 | |
| | 182 | This is a hook to cause an autoindent on a particular character. |
| | 183 | Note that the hook can do more than that -- it can insert or delete |
| | 184 | characters as well. |
| | 185 | |
| | 186 | This takes its name from emacs, where "electric" meant that something |
| | 187 | else happened other than simply inserting the char. |
| | 188 | |
| | 189 | @param stc: stc instance |
| | 190 | |
| | 191 | @param uchar: unicode character that was just typed by the user (note |
| | 192 | that it hasn't been inserted into the document yet.) |
| | 193 | |
| | 194 | @return: True if this method handled the character and the text |
| | 195 | was modified; False if the calling event handler should handle the |
| | 196 | character. |
| | 197 | """ |
| | 198 | return False |
| | 260 | |
| | 261 | def electricChar(self, stc, uchar): |
| | 262 | """Reindent the line and insert a newline when special chars are typed. |
| | 263 | |
| | 264 | Like emacs, a semicolon or curly brace causes the line to be reindented |
| | 265 | and the next line to be indented to the correct column. |
| | 266 | |
| | 267 | @param stc: stc instance |
| | 268 | |
| | 269 | @param uchar: unicode character that was just typed by the user (note |
| | 270 | that it hasn't been inserted into the document yet.) |
| | 271 | |
| | 272 | @return: True if this method handled the character and the text |
| | 273 | was modified; False if the calling event handler should handle the |
| | 274 | character. |
| | 275 | """ |
| | 276 | if uchar == u';' or uchar == '{' or uchar == '}': |
| | 277 | pos = stc.GetCurrentPos() |
| | 278 | s = stc.GetStyleAt(pos) |
| | 279 | if not stc.isStyleComment(s) and not stc.isStyleString(s): |
| | 280 | stc.BeginUndoAction() |
| | 281 | stc.AddText(uchar) |
| | 282 | self.processTab(stc) |
| | 283 | self.processReturn(stc) |
| | 284 | stc.EndUndoAction() |
| | 285 | return True |
| | 286 | return False |