# Ensure \`active_item_index\` doesn't go off the end when closing items · gitcafe/zed

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

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

Visibility: public

Requested revision: 711de5edcb80523f479bf6a8c70f5d5747f6c2ba

Requested commit: 711de5edcb80523f479bf6a8c70f5d5747f6c2ba

Commit: 711de5edcb80523f479bf6a8c70f5d5747f6c2ba

Tree: 8ece563fcba4774ad10bdf8fbaf8351413c31c2d

Author: Antonio Scandurra

Committer: Antonio Scandurra

## Message

```
Ensure `active_item_index` doesn't go off the end when closing items

This fixes a bug introduced in #538, where closing the current tab would hide
all the other tabs, if the current tab was the last one.

Also, this commit manually sets the active item index instead of calling
`Pane::activate_item`: even though this introduces a little bit of duplication,
it prevents us from mistakenly calling `deactivate` on the wrong item. This would
happen because `activate_item` looks at `self.active_item_index` to determine
which item to deactivate before setting the new one. However, that index is
potentially invalid because `::close_items` manipulates the `item_views` vector,
so `activate_item` could end up calling `deactivate` on an item view that was
not active in the first place.

```

## Parents

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

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