Ejemplo n.º 1
0
 def insertText(self, text, indent=True, blankline=False):
     """Insert text in the current document and focuses the document again.
     
     Besides the text, the following keyword arguments may be used:
     
     indent (default: True): The text will be indented if there are one or
         more newlines in it.
     blankline (default: False): A newline will be prepended to text if the
         cursor is currently not on a blank line.
     
     """
     cursor = self.mainwindow().textCursor()
     if blankline and not cursor.hasSelection() and not cursortools.isblank_before(cursor):
         text = '\n' + text
     if indent and '\n' in text:
         import indent
         indent.insert_text(cursor, text)
     else:
         cursor.insertText(text)
Ejemplo n.º 2
0
 def insertText(self, text, indent=True, blankline=False):
     """Insert text in the current document and focuses the document again.
     
     Besides the text, the following keyword arguments may be used:
     
     indent (default: True): The text will be indented if there are one or
         more newlines in it.
     blankline (default: False): A newline will be prepended to text if the
         cursor is currently not on a blank line.
     
     """
     cursor = self.mainwindow().textCursor()
     if blankline and not cursor.hasSelection() and not cursortools.isblank_before(cursor):
         text = '\n' + text
     pos = cursor.selectionStart()
     cursor.insertText(text)
     if indent and '\n' in text:
         cursor.setPosition(pos, cursor.KeepAnchor)
         import indent
         with cursortools.compress_undo(cursor, True):
             indent.re_indent(cursor)