diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cffe55..5f6df89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Procedure when bumping the version number: ### Fixed - Cursor being visible through popups +- Cursor in lists when highlighted item moves off-screen ## v0.4.0 - 2022-09-01 diff --git a/src/ui/widgets/list.rs b/src/ui/widgets/list.rs index 6a586a1..8df110c 100644 --- a/src/ui/widgets/list.rs +++ b/src/ui/widgets/list.rs @@ -1,5 +1,3 @@ -// TODO Fix scrolling by focusing on the cursor like in chat::tree - use std::sync::Arc; use async_trait::async_trait; @@ -36,7 +34,10 @@ impl Cursor { #[derive(Debug)] struct InnerListState { rows: Vec>, + + /// Offset of the first line visible on the screen. offset: usize, + cursor: Option>, make_cursor_visible: bool, } @@ -47,7 +48,7 @@ impl InnerListState { rows: vec![], offset: 0, cursor: None, - make_cursor_visible: false, + make_cursor_visible: true, } } } @@ -172,7 +173,7 @@ impl InnerListState { self.clamp_scrolling(height); self.move_cursor_to_make_it_visible(height); } - self.make_cursor_visible = false; + self.make_cursor_visible = true; } } @@ -190,11 +191,13 @@ impl ListState { pub fn scroll_up(&mut self, amount: usize) { let mut guard = self.0.lock(); guard.offset = guard.offset.saturating_sub(amount); + guard.make_cursor_visible = false; } pub fn scroll_down(&mut self, amount: usize) { let mut guard = self.0.lock(); guard.offset = guard.offset.saturating_add(amount); + guard.make_cursor_visible = false; } }