fix insert/removeLines at the document edges

@lennartcl @javruben