def processReturn(self, stc): """Add a newline and indent to the proper tab level. Indent to the level of the line above. This uses the findIndent method to determine the proper indentation of the line about to be added, inserts the appropriate end-of-line characters, and indents the new line to that indentation level. @param stc: stc of interest """ linesep = stc.getLinesep() stc.BeginUndoAction() # reindent current line (if necessary), then process the return #pos = stc.reindentLine() linenum = stc.GetCurrentLine() pos = stc.GetCurrentPos() col = stc.GetColumn(pos) #linestart = stc.PositionFromLine(linenum) #line = stc.GetLine(linenum)[:pos-linestart] #get info about the current line's indentation ind = stc.GetLineIndentation(linenum) self.dprint("format = %s col=%d ind = %d" % (repr(linesep), col, ind)) stc.SetTargetStart(pos) stc.SetTargetEnd(pos) if col <= ind: newline = linesep + self.getNewLineIndentString(stc, col, ind) elif not pos: newline = linesep else: stc.ReplaceTarget(linesep) pos += len(linesep) end = min(pos + 1, stc.GetTextLength()) # Scintilla always returns a fold level of zero on the last line, # so when trying to indent the last line, must add a newline # character. if pos == end and self.folding_last_line_bug: stc.AddText("\n") end = stc.GetTextLength() # When we insert a new line, the colorization isn't always # immediately updated, so we have to force that here before # calling findIndent to guarantee that the new line will have the # correct fold property set. stc.Colourise(stc.PositionFromLine(linenum), end) stc.SetTargetStart(pos) stc.SetTargetEnd(pos) ind = self.findIndent(stc, linenum + 1) self.dprint("pos=%d ind=%d fold=%d" % (pos, ind, (stc.GetFoldLevel(linenum+1)&wx.stc.STC_FOLDLEVELNUMBERMASK) - wx.stc.STC_FOLDLEVELBASE)) newline = stc.GetIndentString(ind) stc.ReplaceTarget(newline) stc.GotoPos(pos + len(newline)) stc.EndUndoAction()
def processReturn(self, stc): """Add a newline only.""" linesep = stc.getLinesep() stc.AddText(linesep)