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 - General performance and code improvements
- Improved symlinks management - Improved symlinks management
- Possibility to abort file transfers - 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: - Keybindings:
- `E`: Delete file (Same as `DEL`); added because some keyboards don't have `DEL` (hey, that's my MacBook Air's keyboard!) - `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 - `Ctrl+C`: Abort transfer process

View File

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