'Set the cursor of an editor.'

def set_editor_cursor(self, editor, cursor):

    pos = cursor.position()
    anchor = cursor.anchor()
    new_cursor = QTextCursor()
    if (pos == anchor):
        new_cursor.movePosition(pos)
    else:
        new_cursor.movePosition(anchor)
        new_cursor.movePosition(pos, QTextCursor.KeepAnchor)
    editor.setTextCursor(cursor)
