# Buggy code
def select_current_cell(self):
    """Select cell under cursor
    cell = group of lines separated by CELL_SEPARATORS
    returns the textCursor and a boolean indicating if the
    entire file is selected"""
    cursor = self.textCursor()
    cursor.movePosition(QTextCursor.StartOfBlock)
    cur_pos = prev_pos = cursor.position()

    # Moving to the next line that is not a separator, if we are
    # exactly at one of them
    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
    prev_pos = cur_pos
    # If not, move backwards to find the previous separator
    while not self.is_cell_separator(cursor):
        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
            else:
                break
    cursor.setPosition(prev_pos)
    cell_at_file_start = cursor.atStart()
    # Once we find it (or reach the beginning of the file)
    # move to the next separator (or the end of the file)
    # so we can grab the cell contents
    while not self.is_cell_separator(cursor):
        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()
    return cursor, cell_at_file_start and cell_at_file_end


# Traceback (RuntimeError)
File "C:\Users\Chan Chak Tong\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2551, in run_cell
self._run_cell_text(text, block)
File "C:\Users\Chan Chak Tong\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2614, in _run_cell_text
cell_name = self._get_cell_name(block)
File "C:\Users\Chan Chak Tong\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2595, in _get_cell_name
raise RuntimeError('Not a cell?')
RuntimeError: Not a cell?
WARNING:spyder.widgets.github.backend:Failed to send bug report on Github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}

# Fixed code
def select_current_cell(self, cursor=None):
    """
    Select cell under cursor.

    cell = group of lines separated by CELL_SEPARATORS
    returns the textCursor and a boolean indicating if the
    entire file is selected.
    """
    if cursor is None:
        cursor = self.textCursor()
    cursor.movePosition(QTextCursor.StartOfBlock)
    cur_pos = prev_pos = cursor.position()

    # Moving to the next line that is not a separator, if we are
    # exactly at one of them
    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
    prev_pos = cur_pos
    # If not, move backwards to find the previous separator
    while not self.is_cell_separator(cursor):
        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
            else:
                break
    cursor.setPosition(prev_pos)
    cell_at_file_start = cursor.atStart()
    # Once we find it (or reach the beginning of the file)
    # move to the next separator (or the end of the file)
    # so we can grab the cell contents
    while not self.is_cell_separator(cursor):
        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()
    return cursor, cell_at_file_start and cell_at_file_end