diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-07 08:55:13 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-07 12:50:41 +0530 |
commit | 6bd6556449daae40fdabedf64866b641785787f5 (patch) | |
tree | d3fac950bc52df7dc303b157c94673f3f53eac62 | |
parent | 047e424d4fee8061b55a3253b8829ad1ffb84f0c (diff) |
Proper scrolling in mark pane
If something is selected, it behaves like you expect.
Otherwise, it always shows the bottom of the list.
-rw-r--r-- | src/interactive/widgets/mark.rs | 11 | ||||
-rw-r--r-- | tui-react/src/list.rs | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index cf45c59..0fd8113 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -109,10 +109,13 @@ impl MarkPane { .title(&title) .border_style(*border_style) .borders(Borders::ALL); - let entry_in_view = self - .selected - .map(|selected| selected) - .or_else(|| Some(marked.len().saturating_sub(1))); + let entry_in_view = match self.selected { + Some(s) => Some(s), + None => { + self.list.offset = 0; + Some(marked.len().saturating_sub(1)) + } + }; let selected = self.selected; let entries = marked .values() diff --git a/tui-react/src/list.rs b/tui-react/src/list.rs index 45976dd..6c7699a 100644 --- a/tui-react/src/list.rs +++ b/tui-react/src/list.rs @@ -7,7 +7,7 @@ use tui::{ #[derive(Default)] pub struct List { /// The index at which the list last started. Used for scrolling - offset: usize, + pub offset: usize, } impl List { |