diff --git a/assets/settings/default.json b/assets/settings/default.json index 9b023b82c1c..9bb7d056bbf 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1014,6 +1014,11 @@ // // Default: 0 "commit_title_max_length": 0, + // Default action when clicking a changed file in the Git panel. + // + // Choices: project_diff, file_diff, view_file + // Default: project_diff + "entry_primary_click_action": "project_diff", }, "message_editor": { // Whether to automatically replace emoji shortcodes with emoji characters. diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 79a42c8ae34..2e7b273cfa8 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -63,7 +63,8 @@ use prompt_store::RULES_FILE_NAMES; use proto::RpcError; use serde::{Deserialize, Serialize}; use settings::{ - GitPanelGroupBy, GitPanelSortBy, Settings, SettingsStore, StatusStyle, update_settings_file, + GitPanelClickBehavior, GitPanelGroupBy, GitPanelSortBy, Settings, SettingsStore, StatusStyle, + update_settings_file, }; use smallvec::SmallVec; use std::future::Future; @@ -1489,6 +1490,36 @@ impl GitPanel { }); } + fn open_selected_entry_on_click( + &mut self, + secondary: bool, + window: &mut Window, + cx: &mut Context, + ) { + let entry_primary_click_action = + GitPanelSettings::get_global(cx).entry_primary_click_action; + let action = match (entry_primary_click_action, secondary) { + (GitPanelClickBehavior::ProjectDiff, false) => GitPanelClickBehavior::ProjectDiff, + (GitPanelClickBehavior::ProjectDiff, true) => GitPanelClickBehavior::FileDiff, + (GitPanelClickBehavior::FileDiff, false) => GitPanelClickBehavior::FileDiff, + (GitPanelClickBehavior::FileDiff, true) => GitPanelClickBehavior::ProjectDiff, + (GitPanelClickBehavior::ViewFile, false) => GitPanelClickBehavior::ViewFile, + (GitPanelClickBehavior::ViewFile, true) => GitPanelClickBehavior::ProjectDiff, + }; + match action { + GitPanelClickBehavior::ProjectDiff => { + self.open_diff(&Default::default(), window, cx); + self.focus_handle.focus(window, cx); + } + GitPanelClickBehavior::FileDiff => { + self.open_solo_diff(&Default::default(), window, cx); + } + GitPanelClickBehavior::ViewFile => { + self.view_file(&Default::default(), window, cx); + } + } + } + fn revert_selected( &mut self, action: &git::RestoreFile, @@ -6493,12 +6524,7 @@ impl GitPanel { cx.listener(move |this, event: &ClickEvent, window, cx| { this.selected_entry = Some(ix); cx.notify(); - if event.modifiers().secondary() { - this.open_solo_diff(&Default::default(), window, cx) - } else { - this.open_diff(&Default::default(), window, cx); - this.focus_handle.focus(window, cx); - } + this.open_selected_entry_on_click(event.modifiers().secondary(), window, cx); }) }) .on_mouse_down( diff --git a/crates/git_ui/src/git_panel_settings.rs b/crates/git_ui/src/git_panel_settings.rs index 5d104d3fc78..0dbde43cfb5 100644 --- a/crates/git_ui/src/git_panel_settings.rs +++ b/crates/git_ui/src/git_panel_settings.rs @@ -2,7 +2,9 @@ use editor::{EditorSettings, ui_scrollbar_settings_from_raw}; use gpui::Pixels; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use settings::{GitPanelGroupBy, GitPanelSortBy, RegisterSetting, Settings, StatusStyle}; +use settings::{ + GitPanelClickBehavior, GitPanelGroupBy, GitPanelSortBy, RegisterSetting, Settings, StatusStyle, +}; use ui::{ px, scrollbars::{ScrollbarVisibility, ShowScrollbar}, @@ -32,6 +34,7 @@ pub struct GitPanelSettings { pub show_count_badge: bool, pub starts_open: bool, pub commit_title_max_length: usize, + pub entry_primary_click_action: GitPanelClickBehavior, } #[derive(Default)] @@ -80,6 +83,7 @@ impl Settings for GitPanelSettings { show_count_badge: git_panel.show_count_badge.unwrap(), starts_open: git_panel.starts_open.unwrap(), commit_title_max_length: git_panel.commit_title_max_length.unwrap(), + entry_primary_click_action: git_panel.entry_primary_click_action.unwrap(), } } } diff --git a/crates/settings_content/src/settings_content.rs b/crates/settings_content/src/settings_content.rs index b32a86ca45d..a1d1a433815 100644 --- a/crates/settings_content/src/settings_content.rs +++ b/crates/settings_content/src/settings_content.rs @@ -718,6 +718,36 @@ pub struct GitPanelSettingsContent { /// /// Default: 0 pub commit_title_max_length: Option, + + /// Default action when clicking a changed file in the Git panel. + /// + /// Default: project_diff + pub entry_primary_click_action: Option, +} + +#[derive( + Default, + Copy, + Clone, + Debug, + Serialize, + Deserialize, + JsonSchema, + MergeFrom, + PartialEq, + Eq, + strum::VariantArray, + strum::VariantNames, +)] +#[serde(rename_all = "snake_case")] +pub enum GitPanelClickBehavior { + /// Open the project diff, showing all changed files. + #[default] + ProjectDiff, + /// Open a single-file diff view. + FileDiff, + /// Open the file in the editor without a diff view. + ViewFile, } #[derive( diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index 80261bb0da9..15f28020c53 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -5776,7 +5776,7 @@ fn panels_page() -> SettingsPage { ] } - fn git_panel_section() -> [SettingsPageItem; 16] { + fn git_panel_section() -> [SettingsPageItem; 17] { [ SettingsPageItem::SectionHeader("Git Panel"), SettingsPageItem::SettingItem(SettingItem { @@ -5992,6 +5992,29 @@ fn panels_page() -> SettingsPage { metadata: None, files: USER, }), + SettingsPageItem::SettingItem(SettingItem { + title: "Primary Click Behavior", + description: "Default action when clicking a changed file in the Git panel.", + field: Box::new(SettingField { + organization_override: None, + json_path: Some("git_panel.entry_primary_click_action"), + pick: |settings_content| { + settings_content + .git_panel + .as_ref()? + .entry_primary_click_action + .as_ref() + }, + write: |settings_content, value, _| { + settings_content + .git_panel + .get_or_insert_default() + .entry_primary_click_action = value; + }, + }), + metadata: None, + files: USER, + }), SettingsPageItem::SettingItem(SettingItem { title: "Show Count Badge", description: "Whether to show a badge on the git panel icon with the count of uncommitted changes.", diff --git a/crates/settings_ui/src/settings_ui.rs b/crates/settings_ui/src/settings_ui.rs index 6e45adc0f4b..fbc06a70166 100644 --- a/crates/settings_ui/src/settings_ui.rs +++ b/crates/settings_ui/src/settings_ui.rs @@ -600,6 +600,7 @@ fn init_renderers(cx: &mut App) { .add_basic_renderer::(render_dropdown) .add_basic_renderer::(render_dropdown) .add_basic_renderer::(render_dropdown) + .add_basic_renderer::(render_dropdown) .add_basic_renderer::(render_dropdown) .add_basic_renderer::(render_dropdown) .add_basic_renderer::(render_dropdown)