Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
sidebar: Make project reordering key-bindable (#62695)
Akihiro Okuno90eb566f3263
diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rsindex 10cec05c5aa..027c3192164 100644--- a/crates/sidebar/src/sidebar.rs+++ b/crates/sidebar/src/sidebar.rs@@ -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_workspacediff --git a/crates/workspace/src/multi_workspace.rs b/crates/workspace/src/multi_workspace.rsindex 78c46a59f2b..1fba90b3728 100644--- a/crates/workspace/src/multi_workspace.rs+++ b/crates/workspace/src/multi_workspace.rs@@ -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);diff --git a/crates/workspace/src/multi_workspace_tests.rs b/crates/workspace/src/multi_workspace_tests.rsindex de65d40ab6b..289d6404231 100644--- a/crates/workspace/src/multi_workspace_tests.rs+++ b/crates/workspace/src/multi_workspace_tests.rs@@ -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);diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex f8341a39a73..c970393f1cc 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -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::{