'Inserts text at the cursor position.
:param text: text to insert
:param keep_position: Flag that specifies if the cursor position must
be kept. Pass False for a regular insert (the cursor will be at
the end of the inserted text).'

def insert_text(self, text, keep_position=True):

    text_cursor = self._editor.textCursor()
    if keep_position:
        s = text_cursor.selectionStart()
        e = text_cursor.selectionEnd()
    text_cursor.insertText(text)
    if keep_position:
        text_cursor.setPosition(s)
        text_cursor.setPosition(e, text_cursor.KeepAnchor)
    self._editor.setTextCursor(text_cursor)
