Fixed a bug with unselected document

When no document is open, and you run, it gives an exception.