diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-08-31 15:11:04 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-08-31 15:11:04 -0400 |
commit | 596ced65ae6ae59f4e1ac2ed60246a4c5943a919 (patch) | |
tree | 2ef1bc6974bc2fd9b4ec5ce3c27cbe20d40b2b76 /src/commands | |
parent | dc5c3c96dbd4948b1be7194c2f86d473d935e199 (diff) |
tab_switch_index can open more than 1 tab if given number is larger
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/tab_ops.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs index 24a866f..bfd1d11 100644 --- a/src/commands/tab_ops.rs +++ b/src/commands/tab_ops.rs @@ -3,7 +3,7 @@ use std::path; use uuid::Uuid; use crate::context::AppContext; -use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; +use crate::error::JoshutoResult; use crate::history::DirectoryHistory; use crate::tab::{JoshutoTab, TabHomePage}; @@ -78,19 +78,16 @@ pub fn tab_switch(offset: i32, context: &mut AppContext) -> std::io::Result<()> } pub fn tab_switch_index(new_index: usize, context: &mut AppContext) -> JoshutoResult { - if new_index <= context.tab_context_ref().len() { + let num_tabs = context.tab_context_ref().len(); + if new_index <= num_tabs { _tab_switch(new_index - 1, context)?; - Ok(()) - } else if new_index == context.tab_context_ref().len() + 1 { - new_tab(context)?; + } else if new_index > num_tabs { + for _ in 0..(new_index - num_tabs) { + new_tab(context)?; + } _tab_switch(new_index - 1, context)?; - Ok(()) - } else { - Err(JoshutoError::new( - JoshutoErrorKind::InvalidParameters, - format!("No tab with index {}", new_index), - )) } + Ok(()) } pub fn new_tab_home_path(context: &AppContext) -> path::PathBuf { |