bugfix: fix loop scrolling at the beginning/end of the document