ScrollOffset icon indicating copy to clipboard operation
ScrollOffset copied to clipboard

scroll_to ignores a target of 0: top margin is one line short on line margin+1

Open dpc00 opened this issue 1 month ago • 0 comments

Claude reports: scroll_to ignores a target of 0, so the top margin is one line short when the cursor is on line vertical_margin + 1.

Tested ScrollOffset 2015.03.04.02.36.40 from Package Control on Sublime Text build 4215 (Windows), default settings (vertical_margin 5), a 300-line file. Moving the cursor down with the Down key and then back up, the margin works (ScrollOffset does work on this build). But when the cursor comes back up to line 6, the view's top line is line 2, so only 4 lines are above the cursor instead of 5. One line further up (line 5) it scrolls to the top as it should.

Cause: in scroll_to

viewport_position[0] = max(horizontal or viewport_position[0], 0)
viewport_position[1] = vertical or viewport_position[1]

vertical is top - TOP_DIST, which is exactly 0 when the cursor is on line margin + 1, and 0 or viewport_position[1] keeps the old position. The same happens for horizontal being 0.

Fix I tested (loose copy of scroll_offset.py):

viewport_position[0] = max(viewport_position[0] if horizontal is None else horizontal, 0)
if vertical is not None:
    viewport_position[1] = vertical

With that, the cursor on line 6 gives a view starting at line 1.

dpc00 avatar Oct 26 '26 19:10 dpc00