mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
parent
923bed9abf
commit
3ec47ced67
2 changed files with 19 additions and 16 deletions
|
|
@ -16,6 +16,7 @@ use crate::{
|
|||
use anyhow::Result;
|
||||
use asyncgit::{hash, StatusItem, StatusItemType};
|
||||
use crossterm::event::Event;
|
||||
use std::cell::Cell;
|
||||
use std::{borrow::Cow, convert::From, path::Path};
|
||||
use tui::{backend::Backend, layout::Rect, widgets::Text, Frame};
|
||||
|
||||
|
|
@ -28,6 +29,7 @@ pub struct FileTreeComponent {
|
|||
show_selection: bool,
|
||||
queue: Option<Queue>,
|
||||
theme: SharedTheme,
|
||||
scroll_top: Cell<usize>,
|
||||
}
|
||||
|
||||
impl FileTreeComponent {
|
||||
|
|
@ -46,6 +48,7 @@ impl FileTreeComponent {
|
|||
show_selection: focus,
|
||||
queue,
|
||||
theme,
|
||||
scroll_top: Cell::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -247,12 +250,25 @@ impl DrawableComponent for FileTreeComponent {
|
|||
},
|
||||
);
|
||||
|
||||
let select = self
|
||||
.tree
|
||||
.selection
|
||||
.map(|idx| idx - selection_offset)
|
||||
.unwrap_or_default();
|
||||
let tree_height = r.height.saturating_sub(2) as usize;
|
||||
|
||||
self.scroll_top.set(ui::calc_scroll_top(
|
||||
self.scroll_top.get(),
|
||||
tree_height,
|
||||
select,
|
||||
));
|
||||
|
||||
ui::draw_list(
|
||||
f,
|
||||
r,
|
||||
self.title.as_str(),
|
||||
items,
|
||||
self.tree.selection.map(|idx| idx - selection_offset),
|
||||
items.skip(self.scroll_top.get()),
|
||||
Some(select),
|
||||
self.focused,
|
||||
&self.theme,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -49,21 +49,8 @@ where
|
|||
L: Iterator<Item = Text<'b>>,
|
||||
{
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let list_area = match self.block {
|
||||
Some(b) => b.inner(area),
|
||||
None => area,
|
||||
};
|
||||
|
||||
let list_height = list_area.height as usize;
|
||||
|
||||
let offset = if self.scroll >= list_height {
|
||||
self.scroll - list_height + 1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
// Render items
|
||||
List::new(self.items.skip(offset as usize))
|
||||
List::new(self.items)
|
||||
.block(self.block.unwrap_or_default())
|
||||
.style(self.style)
|
||||
.render(area, buf);
|
||||
|
|
|
|||
Loading…
Reference in a new issue