Add git: open modified files action (#32347)

Ported over a vscode/cursor command that I like using : )

Release Notes:

- Added "open modified files" command
This commit is contained in:
Gabe Shahbazian 2025-06-12 10:56:10 -07:00 committed by GitHub
parent 0ee6a90912
commit c13be165cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 1 deletions

View file

@ -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",

View file

@ -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",

View file

@ -57,6 +57,7 @@ actions!(
ExpandCommitEditor,
GenerateCommitMessage,
Init,
OpenModifiedFiles,
]
);

View file

@ -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<Workspace>,
) {
let Some(panel) = workspace.panel::<git_panel::GitPanel>(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)
}