sidebar: Make project reordering key-bindable (#62695)
# Objective - The sidebar already supports moving project groups through its **Move Up** and **Move Down** context-menu entries, but those entries use callbacks that cannot be referenced from `keymap.json`. Moving a project several positions therefore requires reopening the menu for every step. - Follow-up to #57448. Related to #61647. ## Solution - Add `multi_workspace::MoveProjectUp` and `multi_workspace::MoveProjectDown` actions. The handlers resolve the active project group and delegate to the existing `MultiWorkspace` reordering methods, keeping ordering and persistence behavior unchanged. - Associate the actions with the existing context-menu entries so configured shortcuts are shown alongside the menu commands. The menu callbacks still operate on the project that was clicked. ## Testing - Added a GPUI test that dispatches both actions and verifies that the active project group moves in the expected direction and remains unchanged at list boundaries: - `cargo test -p workspace test_move_active_project_group_actions -- --nocapture` - Manually verified on macOS with an isolated Zed user-data directory and three project folders: - Assigned custom shortcuts to both actions in `keymap.json`. - Confirmed that the active project moves up and down in the sidebar. - Ran formatting, compilation, and lint checks: - `cargo fmt --all -- --check` - `cargo check -p sidebar` - `./script/clippy -p workspace -p sidebar -p gpui_platform --features gpui_platform/runtime_shaders` ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase <details> <summary>Move projects with custom keybindings</summary> https://github.com/user-attachments/assets/09432817-318b-484e-b630-a6012e9599cd </details> --- Release Notes: - Sidebar: Added key-bindable actions for moving projects up and down.
This commit is contained in:
1 parent
5b85565d93
commit
74247e797e
4 files changed
+77
-9
No files matched your search
@@ -63,10 +63,10 @@ use unicode_segmentation::UnicodeSegmentation as _;
|
||||
use util::ResultExt as _;
|
||||
use util::path_list::PathList;
|
||||
use workspace::{
|
||||
CloseWindow, FocusWorkspaceSidebar, MultiWorkspace, MultiWorkspaceEvent, NextProject,
|
||||
NextThread, Open, OpenMode, PreviousProject, PreviousThread, ProjectGroupKey, RemovalIntent,
|
||||
SaveIntent, Sidebar as WorkspaceSidebar, SidebarSide, Toast, ToggleWorkspaceSidebar, Workspace,
|
||||
notifications::NotificationId, sidebar_side_context_menu,
|
||||
CloseWindow, FocusWorkspaceSidebar, MoveProjectDown, MoveProjectUp, MultiWorkspace,
|
||||
MultiWorkspaceEvent, NextProject, NextThread, Open, OpenMode, PreviousProject, PreviousThread,
|
||||
ProjectGroupKey, RemovalIntent, SaveIntent, Sidebar as WorkspaceSidebar, SidebarSide, Toast,
|
||||
ToggleWorkspaceSidebar, Workspace, notifications::NotificationId, sidebar_side_context_menu,
|
||||
};
|
||||
|
||||
use git_ui_core::worktree_service::{RemoteBranchName, worktree_create_targets};
|
||||
@@ -3073,6 +3073,7 @@ impl Sidebar {
|
||||
this.separator()
|
||||
.item(
|
||||
ContextMenuEntry::new("Move Up")
|
||||
.action(Box::new(MoveProjectUp))
|
||||
.disabled(!can_move_up)
|
||||
.handler(move |_window, cx| {
|
||||
move_up_multi_workspace
|
||||
@@ -3087,6 +3088,7 @@ impl Sidebar {
|
||||
)
|
||||
.item(
|
||||
ContextMenuEntry::new("Move Down")
|
||||
.action(Box::new(MoveProjectDown))
|
||||
.disabled(!can_move_down)
|
||||
.handler(move |_window, cx| {
|
||||
move_down_multi_workspace
|
||||
|
||||
@@ -46,6 +46,10 @@ actions!(
|
||||
NextProject,
|
||||
/// Activates the previous project in the sidebar.
|
||||
PreviousProject,
|
||||
/// Moves the active project up in the sidebar.
|
||||
MoveProjectUp,
|
||||
/// Moves the active project down in the sidebar.
|
||||
MoveProjectDown,
|
||||
/// Activates the next thread in sidebar order.
|
||||
NextThread,
|
||||
/// Activates the previous thread in sidebar order.
|
||||
@@ -2109,6 +2113,18 @@ impl Render for MultiWorkspace {
|
||||
}
|
||||
}),
|
||||
)
|
||||
.on_action(
|
||||
cx.listener(|this: &mut Self, _: &MoveProjectUp, _window, cx| {
|
||||
let key = this.project_group_key_for_workspace(this.workspace(), cx);
|
||||
this.move_project_group_up(&key, cx);
|
||||
}),
|
||||
)
|
||||
.on_action(
|
||||
cx.listener(|this: &mut Self, _: &MoveProjectDown, _window, cx| {
|
||||
let key = this.project_group_key_for_workspace(this.workspace(), cx);
|
||||
this.move_project_group_down(&key, cx);
|
||||
}),
|
||||
)
|
||||
.on_action(cx.listener(|this: &mut Self, _: &NextThread, window, cx| {
|
||||
if let Some(sidebar) = &this.sidebar {
|
||||
sidebar.cycle_thread(true, window, cx);
|
||||
|
||||
@@ -221,6 +221,56 @@ async fn test_project_group_keys_add_workspace(cx: &mut TestAppContext) {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_move_active_project_group_actions(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
let fs = FakeFs::new(cx.executor());
|
||||
fs.insert_tree("/root_a", json!({ "file.txt": "" })).await;
|
||||
fs.insert_tree("/root_b", json!({ "file.txt": "" })).await;
|
||||
let project_a = Project::test(fs.clone(), ["/root_a".as_ref()], cx).await;
|
||||
let project_b = Project::test(fs, ["/root_b".as_ref()], cx).await;
|
||||
|
||||
let key_a = project_a.read_with(cx, |project, cx| project.project_group_key(cx));
|
||||
let key_b = project_b.read_with(cx, |project, cx| project.project_group_key(cx));
|
||||
|
||||
let (multi_workspace, cx) =
|
||||
cx.add_window_view(|window, cx| MultiWorkspace::test_new(project_a, window, cx));
|
||||
multi_workspace.update_in(cx, |multi_workspace, window, cx| {
|
||||
multi_workspace.test_add_workspace(project_b, window, cx);
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
multi_workspace.read_with(cx, |multi_workspace, _| {
|
||||
multi_workspace.project_group_keys()
|
||||
}),
|
||||
vec![key_b.clone(), key_a.clone()]
|
||||
);
|
||||
|
||||
cx.dispatch_action(MoveProjectDown);
|
||||
assert_eq!(
|
||||
multi_workspace.read_with(cx, |multi_workspace, _| {
|
||||
multi_workspace.project_group_keys()
|
||||
}),
|
||||
vec![key_a.clone(), key_b.clone()]
|
||||
);
|
||||
|
||||
cx.dispatch_action(MoveProjectDown);
|
||||
assert_eq!(
|
||||
multi_workspace.read_with(cx, |multi_workspace, _| {
|
||||
multi_workspace.project_group_keys()
|
||||
}),
|
||||
vec![key_a.clone(), key_b.clone()]
|
||||
);
|
||||
|
||||
cx.dispatch_action(MoveProjectUp);
|
||||
assert_eq!(
|
||||
multi_workspace.read_with(cx, |multi_workspace, _| {
|
||||
multi_workspace.project_group_keys()
|
||||
}),
|
||||
vec![key_b, key_a]
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_open_new_window_does_not_open_sidebar_on_existing_window(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
|
||||
@@ -31,11 +31,11 @@ mod workspace_settings;
|
||||
|
||||
pub use dock::Panel;
|
||||
pub use multi_workspace::{
|
||||
CloseWorkspaceSidebar, DraggedSidebar, FocusWorkspaceSidebar, MoveProjectToNewWindow,
|
||||
MultiWorkspace, MultiWorkspaceEvent, NewThread, NextProject, NextThread, PreviousProject,
|
||||
PreviousThread, ProjectGroup, ProjectGroupKey, RemovalIntent, SerializedProjectGroupState,
|
||||
Sidebar, SidebarEvent, SidebarHandle, SidebarRenderState, SidebarSide, ToggleWorkspaceSidebar,
|
||||
sidebar_side_context_menu,
|
||||
CloseWorkspaceSidebar, DraggedSidebar, FocusWorkspaceSidebar, MoveProjectDown,
|
||||
MoveProjectToNewWindow, MoveProjectUp, MultiWorkspace, MultiWorkspaceEvent, NewThread,
|
||||
NextProject, NextThread, PreviousProject, PreviousThread, ProjectGroup, ProjectGroupKey,
|
||||
RemovalIntent, SerializedProjectGroupState, Sidebar, SidebarEvent, SidebarHandle,
|
||||
SidebarRenderState, SidebarSide, ToggleWorkspaceSidebar, sidebar_side_context_menu,
|
||||
};
|
||||
pub use path_list::{PathList, SerializedPathList};
|
||||
pub use remote::{
|
||||
|
||||
Reference in new issue
Block a user