fix search range to prevent out of bounds

Inserting a new line at end of document will throw an out-of-bounds
exception