def select_all_smart(self):
        """ Select current cell, or, if already selected, the whole document.
        """
        c = self._get_cursor()
        sel_range = c.selectionStart(), c.selectionEnd()

        c.clearSelection()
        c.setPosition(self._get_prompt_cursor().position())
        c.setPosition(self._get_end_pos(),
                      mode=QtGui.QTextCursor.KeepAnchor)
        new_sel_range = c.selectionStart(), c.selectionEnd()
        if sel_range == new_sel_range:
            # cell already selected, expand selection to whole document
            self.select_document()
        else:
            # set cell selection as active selection
            self._control.setTextCursor(c)
 Select current cell, or, if already selected, the whole document.
        
angrmanagement/vendor/qtconsole/console_widget.py