Fix for when document last line visible

When only the last line is visible and the document goes out of focus
it caused an index error.