Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Add action to toggle all diff hunks (#56421)
Neel7a37888f7bc9
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rsindex 01f52e7064d..03557c029f1 100644--- a/crates/editor/src/actions.rs+++ b/crates/editor/src/actions.rs@@ -501,6 +501,9 @@ actions!(ExpandAllDiffHunks,/// Collapses all diff hunks in the editor.CollapseAllDiffHunks,+ /// Toggles all diff hunks in the editor. Collapses all hunks if any are+ /// currently expanded, otherwise expands all hunks.+ ToggleAllDiffHunks,/// Expands macros recursively at cursor position.ExpandMacroRecursively,/// Finds the next match in the search.diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex e04161b6c8a..97380794178 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -468,6 +468,7 @@ impl EditorElement {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::toggle_all_diff_hunks);register_action(editor, window, Editor::toggle_review_comments_expanded);register_action(editor, window, Editor::submit_diff_review_comment_action);register_action(editor, window, Editor::edit_review_comment);diff --git a/crates/editor/src/git.rs b/crates/editor/src/git.rsindex 2571c0b2022..16b1bc4daee 100644--- a/crates/editor/src/git.rs+++ b/crates/editor/src/git.rs@@ -759,6 +759,19 @@ impl Editor {});}+ pub fn toggle_all_diff_hunks(+ &mut self,+ _: &ToggleAllDiffHunks,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ if self.has_any_expanded_diff_hunks(cx) {+ self.collapse_all_diff_hunks(&CollapseAllDiffHunks, window, cx);+ } else {+ self.expand_all_diff_hunks(&ExpandAllDiffHunks, window, cx);+ }+ }+pub(super) fn toggle_selected_diff_hunks(&mut self,_: &ToggleSelectedDiffHunks,