diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index b85b0626b3..62b120efab 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -115,6 +115,7 @@ "ctrl-\"": "editor::ExpandAllDiffHunks", "ctrl-i": "editor::ShowSignatureHelp", "alt-g b": "git::Blame", + "alt-g m": "git::OpenModifiedFiles", "menu": "editor::OpenContextMenu", "shift-f10": "editor::OpenContextMenu", "ctrl-shift-e": "editor::ToggleEditPrediction", diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index 225cddf590..7349745587 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -139,6 +139,7 @@ "cmd-'": "editor::ToggleSelectedDiffHunks", "cmd-\"": "editor::ExpandAllDiffHunks", "cmd-alt-g b": "git::Blame", + "cmd-alt-g m": "git::OpenModifiedFiles", "cmd-i": "editor::ShowSignatureHelp", "f9": "editor::ToggleBreakpoint", "shift-f9": "editor::EditLogBreakpoint", diff --git a/crates/git/src/git.rs b/crates/git/src/git.rs index fb7bca2144..e2c6e54993 100644 --- a/crates/git/src/git.rs +++ b/crates/git/src/git.rs @@ -57,6 +57,7 @@ actions!( ExpandCommitEditor, GenerateCommitMessage, Init, + OpenModifiedFiles, ] ); diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index 2429145720..d0c6792ceb 100644 --- a/crates/git_ui/src/git_ui.rs +++ b/crates/git_ui/src/git_ui.rs @@ -10,7 +10,7 @@ use git::{ status::{FileStatus, StatusCode, UnmergedStatus, UnmergedStatusCode}, }; use git_panel_settings::GitPanelSettings; -use gpui::{Action, App, FocusHandle, actions}; +use gpui::{Action, App, Context, FocusHandle, Window, actions}; use onboarding::GitOnboardingModal; use project_diff::ProjectDiff; use ui::prelude::*; @@ -142,10 +142,41 @@ pub fn init(cx: &mut App) { panel.git_init(window, cx); }); }); + workspace.register_action(|workspace, _: &git::OpenModifiedFiles, window, cx| { + open_modified_files(workspace, window, cx); + }); }) .detach(); } +fn open_modified_files( + workspace: &mut Workspace, + window: &mut Window, + cx: &mut Context, +) { + let Some(panel) = workspace.panel::(cx) else { + return; + }; + let modified_paths: Vec<_> = panel.update(cx, |panel, cx| { + let Some(repo) = panel.active_repository.as_ref() else { + return Vec::new(); + }; + let repo = repo.read(cx); + repo.cached_status() + .filter_map(|entry| { + if entry.status.is_modified() { + repo.repo_path_to_project_path(&entry.repo_path, cx) + } else { + None + } + }) + .collect() + }); + for path in modified_paths { + workspace.open_path(path, None, true, window, cx).detach(); + } +} + pub fn git_status_icon(status: FileStatus) -> impl IntoElement { GitStatusIcon::new(status) }