'Select cell under cursor in the visible portion of the file
cell = group of lines separated by CELL_SEPARATORS
returns
-the textCursor
-a boolean indicating if the entire file is selected
-a boolean indicating if the entire visible portion of the file is selected'

def select_current_cell_in_visible_portion(self):

    cursor = self.textCursor()
    cursor.movePosition(QTextCursor.StartOfBlock)
    cur_pos = prev_pos = cursor.position()
    beg_pos = self.cursorForPosition(QPoint(0, 0)).position()
    bottom_right = QPoint((self.viewport().width() - 1), (self.viewport().height() - 1))
    end_pos = self.cursorForPosition(bottom_right).position()
    while self.is_cell_separator(cursor):
        cursor.movePosition(QTextCursor.NextBlock)
        prev_pos = cur_pos
        cur_pos = cursor.position()
        if (cur_pos == prev_pos):
            return (cursor, False, False)
    prev_pos = cur_pos
    while ((not self.is_cell_separator(cursor)) and (cursor.position() >= beg_pos)):
        cursor.movePosition(QTextCursor.PreviousBlock)
        prev_pos = cur_pos
        cur_pos = cursor.position()
        if (cur_pos == prev_pos):
            if self.is_cell_separator(cursor):
                return (cursor, False, False)
            else:
                break
    cell_at_screen_start = (cursor.position() <= beg_pos)
    cursor.setPosition(prev_pos)
    cell_at_file_start = cursor.atStart()
    if (not cell_at_file_start):
        cursor.movePosition(QTextCursor.PreviousBlock)
        cursor.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor)
    while ((not self.is_cell_separator(cursor)) and (cursor.position() <= end_pos)):
        cursor.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor)
        cur_pos = cursor.position()
        if (cur_pos == prev_pos):
            cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
            break
        prev_pos = cur_pos
    cell_at_file_end = cursor.atEnd()
    cell_at_screen_end = (cursor.position() >= end_pos)
    return (cursor, (cell_at_file_start and cell_at_file_end), (cell_at_screen_start and cell_at_screen_end))
