mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28: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 anyhow::Result;
|
||||||
use asyncgit::{hash, StatusItem, StatusItemType};
|
use asyncgit::{hash, StatusItem, StatusItemType};
|
||||||
use crossterm::event::Event;
|
use crossterm::event::Event;
|
||||||
|
use std::cell::Cell;
|
||||||
use std::{borrow::Cow, convert::From, path::Path};
|
use std::{borrow::Cow, convert::From, path::Path};
|
||||||
use tui::{backend::Backend, layout::Rect, widgets::Text, Frame};
|
use tui::{backend::Backend, layout::Rect, widgets::Text, Frame};
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ pub struct FileTreeComponent {
|
||||||
show_selection: bool,
|
show_selection: bool,
|
||||||
queue: Option<Queue>,
|
queue: Option<Queue>,
|
||||||
theme: SharedTheme,
|
theme: SharedTheme,
|
||||||
|
scroll_top: Cell<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileTreeComponent {
|
impl FileTreeComponent {
|
||||||
|
|
@ -46,6 +48,7 @@ impl FileTreeComponent {
|
||||||
show_selection: focus,
|
show_selection: focus,
|
||||||
queue,
|
queue,
|
||||||
theme,
|
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(
|
ui::draw_list(
|
||||||
f,
|
f,
|
||||||
r,
|
r,
|
||||||
self.title.as_str(),
|
self.title.as_str(),
|
||||||
items,
|
items.skip(self.scroll_top.get()),
|
||||||
self.tree.selection.map(|idx| idx - selection_offset),
|
Some(select),
|
||||||
self.focused,
|
self.focused,
|
||||||
&self.theme,
|
&self.theme,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -49,21 +49,8 @@ where
|
||||||
L: Iterator<Item = Text<'b>>,
|
L: Iterator<Item = Text<'b>>,
|
||||||
{
|
{
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
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
|
// Render items
|
||||||
List::new(self.items.skip(offset as usize))
|
List::new(self.items)
|
||||||
.block(self.block.unwrap_or_default())
|
.block(self.block.unwrap_or_default())
|
||||||
.style(self.style)
|
.style(self.style)
|
||||||
.render(area, buf);
|
.render(area, buf);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue