Fix bug where searching on the last line of file crashes the IDE.

- Also, some formatting fixes.