mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
support end button in file tree (#43)
This commit is contained in:
parent
f5795d1fad
commit
061ad37dce
3 changed files with 26 additions and 2 deletions
|
|
@ -361,6 +361,9 @@ impl Component for ChangesComponent {
|
|||
keys::HOME | keys::SHIFT_UP => {
|
||||
self.move_selection(MoveSelection::Home)
|
||||
}
|
||||
keys::END | keys::SHIFT_DOWN => {
|
||||
self.move_selection(MoveSelection::End)
|
||||
}
|
||||
keys::MOVE_LEFT => {
|
||||
self.move_selection(MoveSelection::Left)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,11 +99,9 @@ impl DiffComponent {
|
|||
self.scroll.saturating_add(1),
|
||||
);
|
||||
}
|
||||
|
||||
ScrollType::Up => {
|
||||
self.scroll = self.scroll.saturating_sub(1);
|
||||
}
|
||||
|
||||
ScrollType::Home => self.scroll = 0,
|
||||
ScrollType::End => self.scroll = scroll_max,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub enum MoveSelection {
|
|||
Left,
|
||||
Right,
|
||||
Home,
|
||||
End,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
|
@ -73,6 +74,7 @@ impl StatusTree {
|
|||
self.selection_right(selection)
|
||||
}
|
||||
MoveSelection::Home => SelectionChange::new(0, false),
|
||||
MoveSelection::End => self.selection_end(),
|
||||
};
|
||||
|
||||
let changed_index =
|
||||
|
|
@ -162,6 +164,27 @@ impl StatusTree {
|
|||
SelectionChange::new(new_index, false)
|
||||
}
|
||||
|
||||
fn selection_end(&self) -> SelectionChange {
|
||||
let items_max = self.tree.len().saturating_sub(1);
|
||||
|
||||
let mut new_index = items_max;
|
||||
|
||||
loop {
|
||||
if self.is_visible_index(new_index) {
|
||||
break;
|
||||
}
|
||||
|
||||
if new_index == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
new_index = new_index.saturating_sub(1);
|
||||
new_index = cmp::min(new_index, items_max);
|
||||
}
|
||||
|
||||
SelectionChange::new(new_index, false)
|
||||
}
|
||||
|
||||
fn is_visible_index(&self, idx: usize) -> bool {
|
||||
self.tree[idx].info.visible
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue