workspace: Add action to move focused panel to next dock position (#23317)

This Pull Request introduces a new command `workspace: move focused
panel to next position` which finds the currently focused panel, if such
panel exists, and moves it to the next valid dock position, following
the order of `Left → Bottom → Right` and then starting again from the
left position.

In order to achieve this the following changes have been introduced:

* Add a new default implementation for `PanelHandle`, namely
`PanelHandle::move_to_next_position` which leverages
`PanelHandle::position`, `PanelHandle::position_is_valid` and
`PanelHandle::set_position` methods to update the panel's position to
the next valid position.
* Add a new method to the `workspace` module, `
move_focused_panel_to_next_position`, which is responsible for finding
the currently focused panel, if such a panel exists, and calling the
`move_to_next_position` method in the panel's handle.
* Add a new action to the `workspace` module,
`MoveFocusedPanelToNextPosition`, which is handled by the
`move_focused_panel_to_next_position` method.

Tests have also been added to the `workspace` module in order to
guarantee that the action is correctly updating the focused panel's
position.

Here's a quick video of it, in action 🔽 


https://github.com/user-attachments/assets/264d382b-5239-40aa-bc5e-5d569dec0734

Closes #23115 

Release Notes:

- Added new command to move the focused panel to the next valid dock
position – `workspace: move focused panel to next position` .
This commit is contained in:
Dino 2025-01-20 11:07:11 +00:00 committed by GitHub
parent 7302be8ebd
commit 0ff803fe10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 102 additions and 0 deletions

View file

@ -76,6 +76,21 @@ pub trait PanelHandle: Send + Sync {
fn focus_handle(&self, cx: &AppContext) -> FocusHandle;
fn to_any(&self) -> AnyView;
fn activation_priority(&self, cx: &AppContext) -> u32;
fn move_to_next_position(&self, cx: &mut WindowContext) {
let current_position = self.position(cx);
let next_position = [
DockPosition::Left,
DockPosition::Bottom,
DockPosition::Right,
]
.into_iter()
.filter(|position| self.position_is_valid(*position, cx))
.skip_while(|valid_position| *valid_position != current_position)
.nth(1)
.unwrap_or(DockPosition::Left);
self.set_position(next_position, cx);
}
}
impl<T> PanelHandle for View<T>