when file index is at the end of the list, moving down will set the current index to the first element and viceversa

This commit is contained in:
ChristianVisintin 2020-12-13 09:46:36 +01:00
parent db532cc4b7
commit f06f718b47
2 changed files with 22 additions and 12 deletions

View file

@ -14,6 +14,9 @@ Released on 13/12/2020
- General performance and code improvements
- Improved symlinks management
- Possibility to abort file transfers
- Enhancements:
- File explorer:
- when file index is at the end of the list, moving down will set the current index to the first element and viceversa.
- Keybindings:
- `E`: Delete file (Same as `DEL`); added because some keyboards don't have `DEL` (hey, that's my MacBook Air's keyboard!)
- `Ctrl+C`: Abort transfer process

View file

@ -29,9 +29,8 @@ use std::path::PathBuf;
use tui::style::Color;
impl FileTransferActivity {
/// ### read_input_event
///
///
/// Read one event.
/// Returns whether at least one event has been handled
pub(super) fn read_input_event(&mut self) -> bool {
@ -42,10 +41,12 @@ impl FileTransferActivity {
self.handle_input_event(&event);
// Return true
true
} else { // No event
} else {
// No event
false
}
} else { // Error
} else {
// Error
false
}
}
@ -100,15 +101,18 @@ impl FileTransferActivity {
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
KeyCode::Right => self.tab = FileExplorerTab::Remote, // <RIGHT> switch to right tab
KeyCode::Up => {
// Move index up
if self.local.index > 0 {
self.local.index -= 1;
}
// Move index up; or move to the last element if 0
self.local.index = match self.local.index {
0 => self.local.files.len() - 1,
_ => self.local.index - 1,
};
}
KeyCode::Down => {
// Move index down
if self.local.index + 1 < self.local.files.len() {
self.local.index += 1;
} else {
self.local.index = 0; // Move at the beginning of the list
}
}
KeyCode::PageUp => {
@ -289,15 +293,18 @@ impl FileTransferActivity {
KeyCode::Tab => self.switch_input_field(), // <TAB> switch tab
KeyCode::Left => self.tab = FileExplorerTab::Local, // <LEFT> switch to local tab
KeyCode::Up => {
// Move index up
if self.remote.index > 0 {
self.remote.index -= 1;
}
// Move index up; or move to the last element if 0
self.remote.index = match self.remote.index {
0 => self.remote.files.len() - 1,
_ => self.remote.index - 1,
};
}
KeyCode::Down => {
// Move index down
if self.remote.index + 1 < self.remote.files.len() {
self.remote.index += 1;
} else {
self.remote.index = 0; // Move at the beginning of the list
}
}
KeyCode::PageUp => {