Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git: Add setting to hide stage/restore buttons (#56740)
Cameron Mcloughlin80b11f483997
diff --git a/assets/settings/default.json b/assets/settings/default.jsonindex 23b6345896a..b22e8589183 100644--- a/assets/settings/default.json+++ b/assets/settings/default.json@@ -1610,6 +1610,8 @@// Should the name or path be displayed first in the git view.// "path_style": "file_name_first" or "file_path_first""path_style": "file_name_first",+ // Whether to show the stage and restore buttons on diff hunks.+ "show_stage_restore_buttons": true,// Directory where git worktrees are created, relative to the repository// working directory.//diff --git a/crates/editor/src/git.rs b/crates/editor/src/git.rsindex 027a8e8d18e..2571c0b2022 100644--- a/crates/editor/src/git.rs+++ b/crates/editor/src/git.rs@@ -2610,6 +2610,10 @@ pub(super) fn render_diff_hunk_controls(_window: &mut Window,cx: &mut App,) -> AnyElement {+ let show_stage_restore = ProjectSettings::get_global(cx)+ .git+ .show_stage_restore_buttons;+h_flex().h(line_height).mr_1()@@ -2624,79 +2628,88 @@ pub(super) fn render_diff_hunk_controls(.gap_1().block_mouse_except_scroll().shadow_md()- .child(if status.has_secondary_hunk() {- Button::new(("stage", row as u64), "Stage")- .alpha(if status.is_pending() { 0.66 } else { 1.0 })- .tooltip({- let focus_handle = editor.focus_handle(cx);- move |_window, cx| {- Tooltip::for_action_in(- "Stage Hunk",- &::git::ToggleStaged,- &focus_handle,- cx,- )- }- })- .on_click({- let editor = editor.clone();- move |_event, _window, cx| {- editor.update(cx, |editor, cx| {- editor.stage_or_unstage_diff_hunks(- true,- vec![hunk_range.start..hunk_range.start],+ .when(show_stage_restore, |el| {+ el.child(if status.has_secondary_hunk() {+ Button::new(("stage", row as u64), "Stage")+ .alpha(if status.is_pending() { 0.66 } else { 1.0 })+ .tooltip({+ let focus_handle = editor.focus_handle(cx);+ move |_window, cx| {+ Tooltip::for_action_in(+ "Stage Hunk",+ &::git::ToggleStaged,+ &focus_handle,cx,- );- });- }- })- } else {- Button::new(("unstage", row as u64), "Unstage")- .alpha(if status.is_pending() { 0.66 } else { 1.0 })- .tooltip({- let focus_handle = editor.focus_handle(cx);- move |_window, cx| {- Tooltip::for_action_in(- "Unstage Hunk",- &::git::ToggleStaged,- &focus_handle,- cx,- )- }- })- .on_click({- let editor = editor.clone();- move |_event, _window, cx| {- editor.update(cx, |editor, cx| {- editor.stage_or_unstage_diff_hunks(- false,- vec![hunk_range.start..hunk_range.start],+ )+ }+ })+ .on_click({+ let editor = editor.clone();+ move |_event, _window, cx| {+ editor.update(cx, |editor, cx| {+ editor.stage_or_unstage_diff_hunks(+ true,+ vec![hunk_range.start..hunk_range.start],+ cx,+ );+ });+ }+ })+ } else {+ Button::new(("unstage", row as u64), "Unstage")+ .alpha(if status.is_pending() { 0.66 } else { 1.0 })+ .tooltip({+ let focus_handle = editor.focus_handle(cx);+ move |_window, cx| {+ Tooltip::for_action_in(+ "Unstage Hunk",+ &::git::ToggleStaged,+ &focus_handle,cx,- );- });- }- })+ )+ }+ })+ .on_click({+ let editor = editor.clone();+ move |_event, _window, cx| {+ editor.update(cx, |editor, cx| {+ editor.stage_or_unstage_diff_hunks(+ false,+ vec![hunk_range.start..hunk_range.start],+ cx,+ );+ });+ }+ })+ })+ })+ .when(show_stage_restore, |el| {+ el.child(+ Button::new(("restore", row as u64), "Restore")+ .tooltip({+ let focus_handle = editor.focus_handle(cx);+ move |_window, cx| {+ Tooltip::for_action_in(+ "Restore Hunk",+ &::git::Restore,+ &focus_handle,+ cx,+ )+ }+ })+ .on_click({+ let editor = editor.clone();+ move |_event, window, cx| {+ editor.update(cx, |editor, cx| {+ let snapshot = editor.snapshot(window, cx);+ let point = hunk_range.start.to_point(&snapshot.buffer_snapshot());+ editor.restore_hunks_in_ranges(vec![point..point], window, cx);+ });+ }+ })+ .disabled(is_created_file),+ )})- .child(- Button::new(("restore", row as u64), "Restore")- .tooltip({- let focus_handle = editor.focus_handle(cx);- move |_window, cx| {- Tooltip::for_action_in("Restore Hunk", &::git::Restore, &focus_handle, cx)- }- })- .on_click({- let editor = editor.clone();- move |_event, window, cx| {- editor.update(cx, |editor, cx| {- let snapshot = editor.snapshot(window, cx);- let point = hunk_range.start.to_point(&snapshot.buffer_snapshot());- editor.restore_hunks_in_ranges(vec![point..point], window, cx);- });- }- })- .disabled(is_created_file),- ).when(!editor.read(cx).buffer().read(cx).all_diff_hunks_expanded(),|el| {diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rsindex 9258b16eef9..d2dc70b8392 100644--- a/crates/project/src/project_settings.rs+++ b/crates/project/src/project_settings.rs@@ -455,6 +455,10 @@ pub struct GitSettings {////// Default: file_name_firstpub path_style: GitPathStyle,+ /// Whether to show the stage and restore buttons on diff hunks.+ ///+ /// Default: true+ pub show_stage_restore_buttons: bool,/// Directory where git worktrees are created, relative to the repository/// working directory. When the resolved directory is outside the project/// root, the project's directory name is automatically appended so that@@ -651,6 +655,7 @@ impl Settings for ProjectSettings {},hunk_style: git.hunk_style.unwrap(),path_style: git.path_style.unwrap().into(),+ show_stage_restore_buttons: git.show_stage_restore_buttons.unwrap_or(true),worktree_directory: git.worktree_directory.clone()diff --git a/crates/settings_content/src/project.rs b/crates/settings_content/src/project.rsindex 2a33373a853..93ef9a36293 100644--- a/crates/settings_content/src/project.rs+++ b/crates/settings_content/src/project.rs@@ -500,6 +500,10 @@ pub struct GitSettings {////// Default: file_name_firstpub path_style: Option<GitPathStyle>,+ /// Whether to show the stage and restore buttons on diff hunks.+ ///+ /// Default: true+ pub show_stage_restore_buttons: Option<bool>,/// Directory where git worktrees are created, relative to the repository/// working directory.///diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rsindex e3fc2fce14c..eafd7ed93bb 100644--- a/crates/settings_ui/src/page_data.rs+++ b/crates/settings_ui/src/page_data.rs@@ -7280,7 +7280,7 @@ fn version_control_page() -> SettingsPage {]}- fn git_hunks_section() -> [SettingsPageItem; 3] {+ fn git_hunks_section() -> [SettingsPageItem; 4] {[SettingsPageItem::SectionHeader("Git Hunks"),SettingsPageItem::SettingItem(SettingItem {@@ -7309,6 +7309,28 @@ fn version_control_page() -> SettingsPage {metadata: None,files: USER,}),+ SettingsPageItem::SettingItem(SettingItem {+ title: "Show Stage/Restore Buttons",+ description: "Whether to show the stage and restore buttons on diff hunks.",+ field: Box::new(SettingField {+ json_path: Some("git.show_stage_restore_buttons"),+ pick: |settings_content| {+ settings_content+ .git+ .as_ref()?+ .show_stage_restore_buttons+ .as_ref()+ },+ write: |settings_content, value, _| {+ settings_content+ .git+ .get_or_insert_default()+ .show_stage_restore_buttons = value;+ },+ }),+ metadata: None,+ files: USER,+ }),]}