File list can now be rewinded

This commit is contained in:
veeso 2021-09-28 12:59:43 +02:00
parent b9a0e516c6
commit f3e694d3d6
2 changed files with 26 additions and 12 deletions

View File

@ -50,9 +50,10 @@ Released on ??
- Added a new key in themes: `misc_info_dialog`: if your theme won't load, just reload it. If you're using a customised theme, you can add to it the missing key via a text editor. Just edit the `theme.toml` in your `$CONFIG_DIR/termscp/theme.toml` and add `misc_info_dialog` (Read more in manual at Themes).
- Enhancements:
- Reuse mounts in UI, in order to reduce executable size
- File list can now be "rewinded", which means that moving with arrows will now allow you to go from top to bottom of the list pressing `<UP>` and viceversa pressing `<DOWN>`.
- Dependencies:
- Added `rust-s3 0.27-rc4`
- Added `notify_rust 4.5.3`
- Added `rust-s3 0.27-rc4`
- Added `self_update 0.27.0`
- Updated `argh` to `0.1.6`
- Updated `dirs` to `4.0.0`

View File

@ -188,21 +188,27 @@ impl OwnStates {
/// ### incr_list_index
///
/// Incremenet list index
pub fn incr_list_index(&mut self) {
/// Incremenet list index.
/// If `can_rewind` is `true` the index rewinds when boundary is reached
pub fn incr_list_index(&mut self, can_rewind: bool) {
// Check if index is at last element
if self.list_index + 1 < self.list_len() {
self.list_index += 1;
} else if can_rewind {
self.list_index = 0;
}
}
/// ### decr_list_index
///
/// Decrement list index
pub fn decr_list_index(&mut self) {
/// If `can_rewind` is `true` the index rewinds when boundary is reached
pub fn decr_list_index(&mut self, can_rewind: bool) {
// Check if index is bigger than 0
if self.list_index > 0 {
self.list_index -= 1;
} else if self.list_len() > 0 && can_rewind {
self.list_index = self.list_len() - 1;
}
}
@ -388,25 +394,25 @@ impl Component for FileList {
match key.code {
KeyCode::Down => {
// Update states
self.states.incr_list_index();
self.states.incr_list_index(true);
Msg::None
}
KeyCode::Up => {
// Update states
self.states.decr_list_index();
self.states.decr_list_index(true);
Msg::None
}
KeyCode::PageDown => {
// Update states
for _ in 0..8 {
self.states.incr_list_index();
self.states.incr_list_index(false);
}
Msg::None
}
KeyCode::PageUp => {
// Update states
for _ in 0..8 {
self.states.decr_list_index();
self.states.decr_list_index(false);
}
Msg::None
}
@ -525,14 +531,21 @@ mod tests {
assert_eq!(states.selected[0], 4);
// Index
states.init_list_states(2);
states.incr_list_index();
// Incr
states.incr_list_index(false);
assert_eq!(states.list_index(), 1);
states.incr_list_index();
states.incr_list_index(false);
assert_eq!(states.list_index(), 1);
states.decr_list_index();
states.incr_list_index(true);
assert_eq!(states.list_index(), 0);
states.decr_list_index();
// Decr
states.list_index = 1;
states.decr_list_index(false);
assert_eq!(states.list_index(), 0);
states.decr_list_index(false);
assert_eq!(states.list_index(), 0);
states.decr_list_index(true);
assert_eq!(states.list_index(), 1);
// Try fixing index
states.init_list_states(5);
states.list_index = 4;