@@ -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, _)| {