Ensure pane: swap item right does not panic (#36765)

This fixes a panic I randomly ran into whilst mistyping in the command
palette: I accidentally ran `pane: swap item right`in a state where no
items were opened in my active pane. We were checking for `index + 1 ==
self.items.len()` there when it really should be `>=`, as otherwise in
the case of no items this panics.

This PR fixes the bug, adds a test for both the panic as well as the
actions themselves (they were untested previously). Lastly (and mostly),
this also cleans up a bit around existing actions to update them with
how we generally handle actions now.

Release Notes:

- Fixed a panic that could occur with the `pane: swap item right`
action.
This commit is contained in:
Finn Evers 2025-08-22 23:28:55 +02:00 committed by GitHub
parent f649c31bf9
commit e6267c42f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 110 additions and 57 deletions

View file

@ -3905,7 +3905,7 @@ pub mod tests {
assert_eq!(workspace.active_pane(), &second_pane);
second_pane.update(cx, |this, cx| {
assert_eq!(this.active_item_index(), 1);
this.activate_prev_item(false, window, cx);
this.activate_previous_item(&Default::default(), window, cx);
assert_eq!(this.active_item_index(), 0);
});
workspace.activate_pane_in_direction(workspace::SplitDirection::Left, window, cx);
@ -3940,7 +3940,9 @@ pub mod tests {
// Focus the second pane's non-search item
window
.update(cx, |_workspace, window, cx| {
second_pane.update(cx, |pane, cx| pane.activate_next_item(true, window, cx));
second_pane.update(cx, |pane, cx| {
pane.activate_next_item(&Default::default(), window, cx)
});
})
.unwrap();