Fix wrong main view content after pressing e in a stack of branches (#4450)

- **PR Description**

When pressing `e` (or `i`) in a stack of branches, we take care of
maintaining the selected commit (as of #2954 for `e`, and #3247 for
`i`), to account for the selection index changing because of added
update-ref todos. This is great, however we missed that the main view
diff now shows the wrong commit, which is very confusing. I'm surprised
that this hasn't been noticed yet.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
This commit is contained in:
Stefan Haller 2025-04-08 16:17:14 +02:00 committed by GitHub
commit 6fb7942500
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View file

@ -608,6 +608,7 @@ func (self *LocalCommitsController) restoreSelectionRangeAndMode(selectionRangeA
})
if ok1 && ok2 {
self.context().SetSelectionRangeAndMode(newSelectedIdx, newRangeStartIdx, selectionRangeAndMode.mode)
self.context().HandleFocus(types.OnFocusOpts{})
}
}

View file

@ -48,6 +48,9 @@ var DropTodoCommitWithUpdateRef = NewIntegrationTest(NewIntegrationTestArgs{
Contains("<-- YOU ARE HERE --- commit 02").IsSelected(),
Contains("CI commit 01"),
).
Tap(func() {
t.Views().Main().Content(Contains("commit 02"))
}).
NavigateToLine(Contains("commit 06")).
Press(keys.Universal.Remove)