Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/git_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ feature_flags.workspace = true
git.workspace = true
git_ui.workspace = true
gpui.workspace = true
menu.workspace = true
project.workspace = true
settings.workspace = true
smallvec.workspace = true
Expand Down
29 changes: 27 additions & 2 deletions crates/git_graph/src/git_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use git_ui::commit_tooltip::CommitAvatar;
use gpui::{
AnyElement, App, Bounds, ClipboardItem, Context, Corner, DefiniteLength, ElementId, Entity,
EventEmitter, FocusHandle, Focusable, FontWeight, Hsla, InteractiveElement, ParentElement,
PathBuilder, Pixels, Point, Render, ScrollWheelEvent, SharedString, Styled, Subscription, Task,
WeakEntity, Window, actions, anchored, deferred, point, px,
PathBuilder, Pixels, Point, Render, ScrollStrategy, ScrollWheelEvent, SharedString, Styled,
Subscription, Task, WeakEntity, Window, actions, anchored, deferred, point, px,
};
use menu::{SelectNext, SelectPrevious};
use project::{
Project,
git_store::{CommitDataState, GitStoreEvent, Repository, RepositoryEvent},
Expand Down Expand Up @@ -844,13 +845,35 @@ impl GitGraph {
.collect()
}

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);
}
}

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);
} else {
self.select_prev(&SelectPrevious, window, cx);
}
}

fn select_entry(&mut self, idx: usize, cx: &mut Context<Self>) {
if self.selected_entry_idx == Some(idx) {
return;
}

self.selected_entry_idx = Some(idx);
self.selected_commit_diff = None;
self.table_interaction_state.update(cx, |state, cx| {
state
.scroll_handle
.scroll_to_item(idx, ScrollStrategy::Nearest);
cx.notify();
});

let Some(commit) = self.graph_data.commits.get(idx) else {
return;
Expand Down Expand Up @@ -1604,6 +1627,8 @@ impl Render for GitGraph {
.bg(cx.theme().colors().editor_background)
.key_context("GitGraph")
.track_focus(&self.focus_handle)
.on_action(cx.listener(Self::select_prev))
.on_action(cx.listener(Self::select_next))
.child(content)
.children(self.context_menu.as_ref().map(|(menu, position, _)| {
deferred(
Expand Down