Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git_graph: Add select first & last actions (#50956)
Remco Smits95aa4f274daf
diff --git a/crates/git_graph/src/git_graph.rs b/crates/git_graph/src/git_graph.rsindex 90ccf94f5f9..12ed44cd7ec 100644--- a/crates/git_graph/src/git_graph.rs+++ b/crates/git_graph/src/git_graph.rs@@ -15,7 +15,7 @@ use gpui::{px, uniform_list,};use language::line_diff;-use menu::{Cancel, SelectNext, SelectPrevious};+use menu::{Cancel, SelectFirst, SelectLast, SelectNext, SelectPrevious};use project::{Project,git_store::{@@ -1171,22 +1171,35 @@ impl GitGraph {cx.notify();}- fn select_prev(&mut self, _: &SelectPrevious, _window: &mut Window, cx: &mut Context<Self>) {+ fn select_first(&mut self, _: &SelectFirst, _window: &mut Window, cx: &mut Context<Self>) {+ self.select_entry(0, cx);+ }++ fn select_prev(&mut self, _: &SelectPrevious, window: &mut Window, cx: &mut Context<Self>) {if let Some(selected_entry_idx) = &self.selected_entry_idx {self.select_entry(selected_entry_idx.saturating_sub(1), cx);} else {- self.select_entry(0, cx);+ self.select_first(&SelectFirst, window, cx);}}fn select_next(&mut self, _: &SelectNext, window: &mut Window, cx: &mut Context<Self>) {if let Some(selected_entry_idx) = &self.selected_entry_idx {- self.select_entry(selected_entry_idx.saturating_add(1), cx);+ self.select_entry(+ selected_entry_idx+ .saturating_add(1)+ .min(self.graph_data.commits.len().saturating_sub(1)),+ cx,+ );} else {self.select_prev(&SelectPrevious, window, cx);}}+ fn select_last(&mut self, _: &SelectLast, _window: &mut Window, cx: &mut Context<Self>) {+ self.select_entry(self.graph_data.commits.len().saturating_sub(1), cx);+ }+fn confirm(&mut self, _: &menu::Confirm, window: &mut Window, cx: &mut Context<Self>) {self.open_selected_commit_view(window, cx);}@@ -2260,8 +2273,10 @@ impl Render for GitGraph {this.open_selected_commit_view(window, cx);})).on_action(cx.listener(Self::cancel))+ .on_action(cx.listener(Self::select_first)).on_action(cx.listener(Self::select_prev)).on_action(cx.listener(Self::select_next))+ .on_action(cx.listener(Self::select_last)).on_action(cx.listener(Self::confirm)).child(content).children(self.context_menu.as_ref().map(|(menu, position, _)| {