Skip to content

Fix a branch checkout leaving its tip off screen - #612

Closed
goneng wants to merge 1 commit into
gitx:masterfrom
goneng:fix-list-not-scrolling-to-the-branch-tip
Closed

goneng wants to merge 1 commit into
gitx:masterfrom
goneng:fix-list-not-scrolling-to-the-branch-tip

Conversation

@goneng

@goneng goneng commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #606.

Changing branch does move the history list to the new branch's tip, but
the rebuild that follows the checkout puts the scroll back at the top and
drops the selection along with it. Restoring that selection put it back
where it stood without bringing it into view, so on any repository whose
branch tips are more than a screen apart the list looked untouched.

Traced on a 60-commit repository, switching to a branch whose tip is row
56 of the list:

scroll oldIndex=55 newIndex=55   visible={{0, -28}, ...}  ->  {{0, 791}, ...}   moved to the tip
restore  currentlySelected=1     visible={{0, 791}, ...}
restore  currentlySelected=0     visible={{0, -28}, ...}   rebuild: selection and scroll both lost
restore  PUTTING BACK selection  visible={{0, -28}, ...}   selection back, scroll left at the top

This comes from #579, not from #582: before it, the
rebuild's dropped selection was re-made by -selectCommit:, which
scrolled as it went. -gitDirForURL: is only read when a document is
opened, and the string it builds is the same one as before - the old code
ran stringWithUTF8String: over the buffer, which stops at the same NUL
that size counts up to.

Test plan

  • PBGitHistorySelectionTests gains 2 tests, of which
    testARestoredSelectionIsBroughtBackIntoView fails on master
  • make unit-test: 51 tests, 0 failures
  • On that 60-commit repository, double-clicking the far branch used to
    leave row 1 at the top of the view; it now scrolls so the selected row
    56 sits inside the viewport

@hannesa2

hannesa2 commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

#606 (comment)

That's why I make a similar pull request to have an artifact to test on my side

Reading the list in again after a checkout puts the scroll back at the
top and drops the selection with it, and putting that selection back
left the commit the list had just moved to below the fold, so changing
branch looked like nothing had happened at all.

* Bring a restored selection into view, the way the re-selection it
  replaced used to
* Leave the list where it stands when the selection was never dropped,
  so an update on its own still cannot move it under the user
@goneng
goneng force-pushed the fix-list-not-scrolling-to-the-branch-tip branch from 327156e to d19449f Compare September 12, 2026 08:42
@goneng
goneng marked this pull request as ready for review September 12, 2026 08:49
@goneng

goneng commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favour of #614, which is the same change on upstream where the CI job can produce an artifact to test.

@goneng goneng closed this Sep 12, 2026
@goneng
goneng deleted the fix-list-not-scrolling-to-the-branch-tip branch September 12, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double click changes branch, but don't update right side

2 participants