mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
use new scroll in files list too
This commit is contained in:
parent
b9c763756a
commit
3a849bc900
2 changed files with 18 additions and 24 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
use super::{
|
use super::{
|
||||||
CommandBlocking, CommandInfo, Component, DrawableComponent,
|
utils::scroll_vertical::VerticalScroll, CommandBlocking,
|
||||||
EventState, SyntaxTextComponent,
|
CommandInfo, Component, DrawableComponent, EventState,
|
||||||
|
SyntaxTextComponent,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
keys::SharedKeyConfig,
|
keys::SharedKeyConfig,
|
||||||
|
|
@ -16,9 +17,7 @@ use asyncgit::{
|
||||||
use crossbeam_channel::Sender;
|
use crossbeam_channel::Sender;
|
||||||
use crossterm::event::Event;
|
use crossterm::event::Event;
|
||||||
use filetreelist::{FileTree, FileTreeItem};
|
use filetreelist::{FileTree, FileTreeItem};
|
||||||
use std::{
|
use std::{collections::BTreeSet, convert::From, path::Path};
|
||||||
cell::Cell, collections::BTreeSet, convert::From, path::Path,
|
|
||||||
};
|
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::{Constraint, Direction, Layout, Rect},
|
layout::{Constraint, Direction, Layout, Rect},
|
||||||
|
|
@ -43,7 +42,7 @@ pub struct RevisionFilesComponent {
|
||||||
files: Vec<TreeFile>,
|
files: Vec<TreeFile>,
|
||||||
current_file: SyntaxTextComponent,
|
current_file: SyntaxTextComponent,
|
||||||
tree: FileTree,
|
tree: FileTree,
|
||||||
scroll_top: Cell<usize>,
|
scroll: VerticalScroll,
|
||||||
revision: Option<CommitId>,
|
revision: Option<CommitId>,
|
||||||
focus: Focus,
|
focus: Focus,
|
||||||
key_config: SharedKeyConfig,
|
key_config: SharedKeyConfig,
|
||||||
|
|
@ -60,7 +59,7 @@ impl RevisionFilesComponent {
|
||||||
Self {
|
Self {
|
||||||
queue: queue.clone(),
|
queue: queue.clone(),
|
||||||
tree: FileTree::default(),
|
tree: FileTree::default(),
|
||||||
scroll_top: Cell::new(0),
|
scroll: VerticalScroll::new(),
|
||||||
current_file: SyntaxTextComponent::new(
|
current_file: SyntaxTextComponent::new(
|
||||||
sender,
|
sender,
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
|
|
@ -168,25 +167,22 @@ impl RevisionFilesComponent {
|
||||||
fn draw_tree<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
|
fn draw_tree<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
|
||||||
let tree_height = usize::from(area.height.saturating_sub(2));
|
let tree_height = usize::from(area.height.saturating_sub(2));
|
||||||
|
|
||||||
let selection = self.tree.visual_selection();
|
self.tree.visual_selection().map_or_else(
|
||||||
let visual_count = selection.map_or_else(
|
|
||||||
|| {
|
|| {
|
||||||
self.scroll_top.set(0);
|
self.scroll.reset();
|
||||||
0
|
|
||||||
},
|
},
|
||||||
|selection| {
|
|selection| {
|
||||||
self.scroll_top.set(ui::calc_scroll_top(
|
self.scroll.update(
|
||||||
self.scroll_top.get(),
|
|
||||||
tree_height,
|
|
||||||
selection.index,
|
selection.index,
|
||||||
));
|
selection.count,
|
||||||
selection.count
|
tree_height,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let items = self
|
let items = self
|
||||||
.tree
|
.tree
|
||||||
.iterate(self.scroll_top.get(), tree_height)
|
.iterate(self.scroll.get(), tree_height)
|
||||||
.map(|(item, selected)| {
|
.map(|(item, selected)| {
|
||||||
Self::tree_item_to_span(item, &self.theme, selected)
|
Self::tree_item_to_span(item, &self.theme, selected)
|
||||||
});
|
});
|
||||||
|
|
@ -213,13 +209,7 @@ impl RevisionFilesComponent {
|
||||||
);
|
);
|
||||||
|
|
||||||
if is_tree_focused {
|
if is_tree_focused {
|
||||||
ui::draw_scrollbar(
|
self.scroll.draw(f, area, &self.theme);
|
||||||
f,
|
|
||||||
area,
|
|
||||||
&self.theme,
|
|
||||||
visual_count.saturating_sub(tree_height),
|
|
||||||
self.scroll_top.get(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ impl VerticalScroll {
|
||||||
self.top.get()
|
self.top.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset(&self) {
|
||||||
|
self.top.set(0);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&self,
|
&self,
|
||||||
selection: usize,
|
selection: usize,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue