# git_ui: Fix select previous selects a non-visible item \(\#49289\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/cd1211f70d86ab42a1f5f0875bbafb36f2dcb700)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: cd1211f70d86ab42a1f5f0875bbafb36f2dcb700

Requested commit: cd1211f70d86ab42a1f5f0875bbafb36f2dcb700

Commit: cd1211f70d86ab42a1f5f0875bbafb36f2dcb700

Tree: fef4415b38328a03f26f988a1928bb465d672862

Author: Remco Smits

Committer: GitHub

## Message

```
git_ui: Fix select previous selects a non-visible item (#49289)

This PR fixes that when you are below a header and want to select a
previous item, we would select a non-visible item because we did a -1 of
the newly selected index, which could end up inside a collapsed
directory.

**Note**: This is only an issue for the git tree view mode.

**Before** (See selection is not visible anymore after select previous,
because it's inside the collapsed directory)


https://github.com/user-attachments/assets/bd032768-b947-45f8-b5a1-6185010202cf

**After** (See selection now selects the first visible item in the list
which is the collapsed directory)


https://github.com/user-attachments/assets/47f67237-be7c-4ef5-8b99-6a3a2b016086

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Git UI: Fix selecting previous item would select a non-visible item if
it's inside a collapsed directory
```

## Parents

- [94400d856e0e0ad263a457c2c412897fe883f3d7](https://git.cafe/gitcafe/zed/commit/94400d856e0e0ad263a457c2c412897fe883f3d7?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/cd1211f70d86ab42a1f5f0875bbafb36f2dcb700?format=markdown)
