From 13fe9938c2b3fe9bd1a3f9e0b018a1085d5e8fa3 Mon Sep 17 00:00:00 2001 From: Josh Piasecki <138541977+FloppyDisco@users.noreply.github.com> Date: Mon, 20 Oct 2025 13:18:01 -0500 Subject: [PATCH] CollapseAllDiffHunks action for editor (#40668) This PR adds a new action `editor::CollapseAllDiffHunks` which will allow the user to choose any keybinding for hiding the Expanded Diff Hunks. --- crates/editor/src/actions.rs | 2 ++ crates/editor/src/editor.rs | 11 +++++++++++ crates/editor/src/element.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index 530a547bb9d28d9dadeb95f5e9e98425eb967a55..810b84efcd40de6e507dfe12b1a1a7f89d2ec4cf 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -458,6 +458,8 @@ actions!( /// Expands all diff hunks in the editor. #[action(deprecated_aliases = ["editor::ExpandAllHunkDiffs"])] ExpandAllDiffHunks, + /// Collapses all diff hunks in the editor. + CollapseAllDiffHunks, /// Expands macros recursively at cursor position. ExpandMacroRecursively, /// Finds all references to the symbol at cursor. diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 18fede90dd344d29dfb2407bce6a06ec875c3a35..20ebff811d544d0261e90c43336e569e9a5700ef 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -18792,6 +18792,17 @@ impl Editor { }); } + pub fn collapse_all_diff_hunks( + &mut self, + _: &CollapseAllDiffHunks, + _window: &mut Window, + cx: &mut Context, + ) { + self.buffer.update(cx, |buffer, cx| { + buffer.collapse_diff_hunks(vec![Anchor::min()..Anchor::max()], cx) + }); + } + pub fn toggle_selected_diff_hunks( &mut self, _: &ToggleSelectedDiffHunks, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 52e73bd01c1712371805610f2aff2de6d7aa2d4b..b80953ad842b5c35dbfbbd8872f329760bd9b7a0 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -493,6 +493,7 @@ impl EditorElement { register_action(editor, window, Editor::stage_and_next); register_action(editor, window, Editor::unstage_and_next); register_action(editor, window, Editor::expand_all_diff_hunks); + register_action(editor, window, Editor::collapse_all_diff_hunks); register_action(editor, window, Editor::go_to_previous_change); register_action(editor, window, Editor::go_to_next_change);