fix(table): keep the viewport in place when stepping across the last row - #1054
Open
cabbagekobe wants to merge 2 commits into
Open
cabbagekobe wants to merge 2 commits into
cabbagekobe wants to merge 2 commits into
Conversation
MoveUp applied the new viewport offset before UpdateViewport re-rendered the row window, so viewport.SetYOffset clamped it against the previous content. From the last row that content is only one row taller than the viewport, so the offset was cut back and the first "up" shifted the whole visible window by a row instead of moving just the cursor. Update the row window first, as MoveDown already does.
MoveDown re-rendered the row window first and then subtracted its step from the viewport's y-offset. In v2, SetContent clamps the y-offset when the content shrinks, which it does as the window's start advances with the cursor. After stepping up two or more rows from the last row, the offset was therefore already reduced by SetContent, and MoveDown reduced it again, scrolling the visible window up by a row instead of just moving the cursor; the next MoveDown put it back. Take the offset before UpdateViewport, as MoveUp already does, so the step is applied to the offset the user actually saw. SetYOffset still clamps the result at the end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1053.
Problem
With a table taller than its viewport, put the cursor on the last row (
G/GotoBottom) and presskonce. The whole visible window shifts up by one row and the cursor stays on the bottom line, instead of the cursor simply moving to the second-to-last line. The secondkonward behaves normally.Repro (30 rows, 5 visible): after
GotoBottomthe view showsr25..r29with the cursor onr29; afterMoveUp(1)it showsr24..r28with the cursor onr28.Cause
MoveUpcomputes the new y-offset and callsviewport.SetYOffsetbeforeUpdateViewportre-renders the row window. In v2SetYOffsetclamps to the current content, which still ends at the previous cursor: from the last row that content is only one row taller than the viewport, so the offset is cut back to 1 and the re-rendered window ends up shifted.In v1
MoveUpassignedviewport.YOffsetdirectly (no clamp), so the bug did not surface there.MoveDownalready callsUpdateViewportfirst, which is whyjis unaffected.Fix
Call
UpdateViewport()beforeSetYOffset()inMoveUp, mirroringMoveDown. The offset computation itself is unchanged.TestMoveUpFromBottomKeepsViewportfails onmainand passes with this change; the existingtabletests still pass.Follow-up: the same clamp bites
MoveDownAfter stepping up two or more rows from the last row,
MoveDown(1)scrolled the window up by one row and the nextMoveDownput it back.MoveDownre-renders first, and v2'sSetContentclamps the y-offset when the window shrinks, so the step was subtracted from an already-clamped offset. The second commit reads the offset beforeUpdateViewport, mirroring theMoveUpchange;TestMoveDownAfterUpsKeepsViewportfails onmainand passes with it.